Filter löschen
Filter löschen

Adding Horizontal Offset Within a Loop

1 Ansicht (letzte 30 Tage)
Rafael Fehér
Rafael Fehér am 8 Jun. 2020
Kommentiert: Adam Danz am 8 Jun. 2020
I need to plot this figure in Matlab:
The code here is simply:
for i=5:16
plot(DataRx(:,i),DataRy(:,i))
hold on
end
Where DataRx and DataRy are two matrices.
But what i really want is to add horizontal offsets to this lines for it not being one over another. Something like this:
But I can only achieve this using a code with no loop, something like this:
plot(DataRx(:,14),DataRy(:,14),DataRx(:,15)+1,DataRy(:,15),DataRx(:,17)+2,DataRy(:,17))
My question is: How can I add these spacings (the +1 and +2 in the code line above) in a loop, so I don't have to write "DataRx(:,14),DataRy(:,14)", "DataRx(:,15)+1,DataRy(:,15)" manually?
Thank you,
Rafael F.

Akzeptierte Antwort

Adam Danz
Adam Danz am 8 Jun. 2020
Create an offset variable that continues to increase within the loop.
hold on
offset = 0;
for i=5:16
plot(DataRx(:,i) + offset, DataRy(:,i))
offset = offset + 1;
end
  2 Kommentare
Rafael Fehér
Rafael Fehér am 8 Jun. 2020
Thank you so much, Mr. Adam
Adam Danz
Adam Danz am 8 Jun. 2020
Glad I could help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by