New Vector

8 Ansichten (letzte 30 Tage)
Jesse
Jesse am 20 Mär. 2012
I am trying to write a for loop and generate a new vector. What notation do I need for the Syb(?) in the following code?
Syb = [];
for m =1:length(I_FinalOut)
for n=1:length(Q_FinalOut)
if I_FinalOut(m) > 0 && Q_FinalOut(n) > 0
Syb(?) = 0
elseif I_FinalOut(m) < 0 && Q_FinalOut(n) > 0
Syb(?) = 1
elseif I_FinalOut(m) > 0 && Q_FinalOut(n) < 0
Syb(?) = 2
elseif I_FinalOut(m) < 0 && Q_FinalOut(n) < 0
Syb(?) = 3
end
end
end
If I use (i), then it goes through my I_FinalOut, and if I use (j) it does the Q_FinalOut. So I am not sure what notation to use to get a new vector Syb of it's own based on the if statement.

Antworten (1)

Aldin
Aldin am 20 Mär. 2012
Hi, i think you need 4 counters, in this case you code will be like this:
Syb = []; counter1 = 0; counter2 = 0; counter3 = 0; counter4 = 0; for m =1:length(I_FinalOut)
for n=1:length(Q_FinalOut)
if I_FinalOut(m) > 0 && Q_FinalOut(n) > 0
counter1 = counter1 + 1;
Syb(counter1) = 0
elseif I_FinalOut(m) < 0 && Q_FinalOut(n) > 0
counter2 = counter 2 + 1;
Syb(Syb(end)+counter2) = 1
elseif I_FinalOut(m) > 0 && Q_FinalOut(n) < 0
counter3 = counter3 + 1;
Syb(Syb(end)+counter3) = 2
elseif I_FinalOut(m) < 0 && Q_FinalOut(n) < 0
counter4 = cpunter4 + 1;
Syb(Syb(end)+counter4) = 3
end
end
end
or other solution if only on if condition is ready for processing (true):
Syb = []; counter1 = 0; counter2 = 0; counter3 = 0; counter4 = 0; for m =1:length(I_FinalOut)
for n=1:length(Q_FinalOut)
if I_FinalOut(m) > 0 && Q_FinalOut(n) > 0
counter1 = counter1 + 1;
Syb(counter1) = 0
elseif I_FinalOut(m) < 0 && Q_FinalOut(n) > 0
counter2 = counter 2 + 1;
Syb(counter2) = 1
elseif I_FinalOut(m) > 0 && Q_FinalOut(n) < 0
counter3 = counter3 + 1;
Syb(counter3) = 2
elseif I_FinalOut(m) < 0 && Q_FinalOut(n) < 0
counter4 = cpunter4 + 1;
Syb(counter4) = 3
end
end
end

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by