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

7 views (last 30 days)
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

Accepted Answer

per isakson
per isakson on 25 Dec 2014
Edited: per isakson on 25 Dec 2014
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!