how to run a loop according to two different index at the same time?

7 次查看(过去 30 天)
For example:
i=[0 1 3 6 10]
j=[1 3 6 10 15]
Normally, when we use
'for index1=i
for index2=i
....
end
end'
then Matlab will firstly set i=0 and then run all the vaules from 1 to 15 in index2, and then goes back to i=1.
However, in my problem, I require that i and j to be executed simultaneously, like: when i=0, j=1, then i=1, j=3.
Anyone can tell me how to do with it?
many thanks

采纳的回答

per isakson
per isakson 2014-12-25
编辑:per isakson 2014-12-25
One way:
ii = [0,1,3,6,10];
jj = [1,3,6,10,15];
for ix = 1 : length(ii)
ii(ix)
jj(ix)
end
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by