MATLAB program design and application (2)

xiaoxiao2021-03-06  68

1-2, repeat command

The simplest repeat command is for-loop, its basic form:

FOR variable = matrix;

Operation;

end

The value of the variable will be set to each line of the matrix to perform an arithmetic pattern between FOR and END. Therefore, if there is no accident, the number of arithmeters will be equal to the number of rows of the matrix.

For example, the following commands generate a harmonic sequence: Harmonic Sequence:

X = Zeros (1,6);% x is a zero matrix of 16

For i = 1: 6,

X (i) = 1 / i;

<

转载请注明原文地址:https://www.9cbs.com/read-90681.html

New Post(0)