matlab - FOR loop won't complete when endval is a vector -
i have loop works fine when
n=20 (i = 1: + 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 , missing 20 further fnew values when n=40. or when
n = [40 20]
the loop stops @ 40 iterations dont want 20 fnew values when n=20 there any, , mean any, way around this? appreciated!
sounds want for
loop go 40 small piece of codes runs i=20? have if
statement lets parts of codes evaluated when i <= 20
. following?
for = 1:n disp(['iteration count =' num2str(i)]) if (i <= 20) x = p + (i * h); fadd = f(x); fnew = fold + fadd; disp(['fnew = ' num2str(fnew)]) fold = fnew; end end
Comments
Post a Comment