How to loop an already looping code, in order to find output convergent value.
Show older comments
%I have code which includes a for and while loop which I have to loop one
%million times, to find a convergent output (probability).
sq=0;
i=1;
while sq<=250
sq(i)=i^2
i=i+1;
end
prime=primes(250)
pos=randi(255,1,1)
position=pos;
for f=2:15
r=randi(2,1,1);
if (position(f-1)==1)
position(f)=2;
elseif (position(f-1)==250)
position(f)=249;
elseif (r==1)
position(f)=position(f-1)+1;
else
position(f)=position(f-1)-1;
end
end
disp('Position = ');
disp(position);
plot(1:length(position),position)
xlabel('time')
ylabel('Position')
probability=abs(pos-position(length(position)))/15*100
%how do I make this entire code, that calculates for a number loop one
%million times and give the final convergent number.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!