for - for loop to repeat specified number

of times - MATLAB (original) (raw)

for loop to repeat specified number of times

Syntax

for index = values statements end

Description

for _`index`_ = _`values`_, _`statements`_, end executes a group of statements in a loop for a specified number of times. values has one of the following forms:

example

Examples

collapse all

Create a Hilbert matrix of order 10.

s = 10; H = zeros(s);

for c = 1:s for r = 1:s H(r,c) = 1/(r+c-1); end end

Step by increments of -0.2, and display the values.

for v = 1.0:-0.2:0.0 disp(v) end

 1

0.8000

0.6000

0.4000

0.2000

 0

for v = [1 5 8 17] disp(v) end

for I = eye(4,3) disp('Current unit vector:') disp(I) end

Tips

Extended Capabilities

expand all

Usage notes and limitations:

Version History

Introduced before R2006a