Читать книгу Applied Numerical Methods Using MATLAB - Won Y. Yang - Страница 26

1.1.9.2 for index=i_0:increment:i_last‐end Loop

Оглавление

A for loop makes a block of statements executed repeatedly for a specified number of times, with its loop index increasing from i_ 0 to a number not greater than i_ last by a specified step ( increment) or by 1 if not specified. The loop iteration normally ends when the loop index reaches i_ last, but it can be stopped by a break statement inside the for loop. The for loop with a positive/negative increment will never be iterated if the last value ( i_ last) of the index is smaller/greater than the starting value ( i_0).

1 (Ex. 6) A for Loop%nm119_6.m: example of for loop point= [76 85 91 65 87]; for n=1:length(point) if point(n)>=80, pf(n,:)= 'pass'; elseif point(n)>=0, pf(n,:)= 'fail'; else %if point(n)<0 pf(n,:)= '????'; fprintf('\n\a Something wrong with the data??\n'); break; end end pf

Applied Numerical Methods Using MATLAB

Подняться наверх