Loop through certain integers and in the order that I specify
The normal loop is
for i=1:50
end
but I want to ex开发者_JAVA技巧ecute 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?
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.
精彩评论