How can I split the excuation of multiple for loops ?

4 views (last 30 days)
If I have two for loops each of them has index values =5 and these loops inside let say outer for loop as illustrated in the code below.
I want to run the first loop after that run the second loop and back to the first loop to run the second index value and back again to the second loop to excute the second index value and so forth. I want show the result in this order,
X1(i)=1, X2(j)=1, X1(i)=2, X2(j)=2, X1(i)=3, X2(j)=3 ,and so on....
.....Thanks in advance for any help and comment
for k = 1:10
for i=1:5
X1(i) = do some calculation % First loop
for j=1:5
X2(j) = do some calculation % Second loop

Accepted Answer

KSSV on 24 Jan 2023
Edited: KSSV on 24 Jan 2023
for k = 1:10
for i=1:5
X1(i) = do some calculation
X2(i) = do some calculation
omar th
omar th on 25 Jan 2023
@Steven Lord Thank you so much for your fast response. I asked the below question but I didn't get any answer and comments maybe my question wasn't clear. So, please if you have time, would you answer me or even just give your opinion ? Thanks in advance

Sign in to comment.

More Answers (0)


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





Community Treasure Hunt

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

Start Hunting!