FOR loop won't complete when endval is a vector
I have a for loop that works fine when
n=20
for (i = 1: i + 1: n - 1)
disp(['Iteration count =' num2str(i)])
x = p + (i * h);
fAdd = f(x);
fNew = fOld + fAdd;
disp(['fNew = ' num2str(fNew)])
fOld = fNew;
end
but when
n = [20 40];
The loop stops after 20 iterations only and is missing 20 further fNew
values for when n=40. Or when
n = [40 20]
The loop stops at 40 iterations but I dont want the extra 20 fNew values
for when n=20 Is there any, and I mean any, way around this? Any help
would be appreciated!
No comments:
Post a Comment