I wonder how it is possible to stop a for loop without using break. I have tried to expand the code with a while loop, but I do not manage to get it to work. Appreciate hints.
n = 20; terskelverdi = 0.1;F = zeros(1,n); F(1) = 1;F(2) = 1;for k = 3:n r = rand(1); if r > terskelverdi F(k) = F(k-1) + F(k-2); else F(k) = F(k-1) - F(k-2); end enddisp(F)figure, plot(F,'g-'), gridtitle('Fibonaccitall med tilfeldigheter opp til "n"')
Best Answer