Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through certain integers and in the order that I specify

Tags:

matlab

The normal loop is

for i=1:50

end

but I want to execute the loop through certain integers and in the order that I specify

for i=4,3,45,34,23,31

end

How can I do that in Matlab?

like image 447
crowso Avatar asked Feb 22 '11 15:02

crowso


1 Answers

That's easy:

for i = [4,3,45,34,23,31]

The argument to for in Matlab is a matrix. 1:50 creates a matrix (vector) of numbers 1..50. It is just a special case of Matlab for-usage.

like image 145
ypnos Avatar answered Sep 20 '22 13:09

ypnos