MATLAB Answers

Running 2 counters in 1 for loop simultaneously

15 views (last 30 days)
Wasim Ramadan
Wasim Ramadan on 28 Apr 2020
Answered: Deepak Gupta on 28 Apr 2020
I am trying to run a for loop that has 2 counters instead of one. Example
for i=1:2 j=0:12:12 ....
So, first iteration i=1 and j=0 second iteration i=2 and j=12

  0 Comments

Sign in to comment.

Answers (1)

Deepak Gupta
Deepak Gupta on 28 Apr 2020
Hi,
you just need to define j outside the loop. And then use it with i as index.
j = 0:12:12;
for i= 1:2
% Write your code here using j with i as subscript.
%for example x(i) = j(i);
end

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!