MATLAB: Why this code is not running ? the workspace remains empty.

matrix

m = zeros(1,163);
count = 1;
flag= 0;
while 1
r = randi([1,326]);
for i = 1:1:count
if(m(1,i)==r)
flag = 1;
end
end
if(flag==0)
m(1,count)=r;
count=count+1;
end
if(count==163)
break;
end
end

Best Answer

Once flag gets set to 1, you don't ever reset it to 0 so you effectively disable the rest of your code and count ceases to increment and you have an infinite loop. So move the flag=0 line to inside your loop. E.g.,
m = zeros(1,163);
count = 1;
while 1
r = randi([1,326]);
flag = 0; % <-- Moved to here
for i = 1:1:count
if(m(1,i)==r)
flag = 1;
end
end
if(flag==0)
m(1,count)=r;
count=count+1;
end
if(count==163) % <-- Is this really what you want?
break;
end
end
Also, your code exits the loop before setting the last element. If you want to set that last element, change your if(count==163) test to if(count==164).
Finally, it looks like you are simply wanting to generate an array of random non-repeating integers between 1 and 326. This entire code could be reduced to this one line:
m = randperm(326,163);
Or if you have an older version of MATLAB:
m = randperm(326);
m = m(1:163);