Basic loop syntax in MATLAB: for k=1:n

What does it mean
for k=1:n

2 Kommentare

mohsen mohsen
mohsen mohsen am 29 Mär. 2021
for i= 1:3
Walter Roberson
Walter Roberson am 29 Mär. 2021
It is as described in the responses rom Sean and I, with n being 3.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Sean de Wolski
Sean de Wolski am 28 Jan. 2011

2 Stimmen

it means that everything between that line
k = 1:n
and
end
will be evaluated with k = every integer between 1 and n.
doc for
for more information
Walter Roberson
Walter Roberson am 28 Jan. 2011

1 Stimme

(Adjusting Sean's answer):
it means that everything between that line
k = 1:n
and
end
will be evaluated with k = every integer starting at 1 and not exceeding n; no iterations will be done at all if n < 1
doc for
for more information

4 Kommentare

Jan
Jan am 28 Jan. 2011
Bearbeitet: Jan am 30 Dez. 2017
If you think Walter's adjustments are peantus, read: http://www.mathworks.com/matlabcentral/newsreader/view_thread/293533
Walter Roberson
Walter Roberson am 28 Jan. 2011
Heh. Somehow I missed that discussion the first time around!
Matt Fig
Matt Fig am 28 Jan. 2011
Jan, how do you remember these things! There are obviously no angry armadillos bouncing around in your head.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 28 Jan. 2011

Kommentiert:

am 29 Mär. 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by