Multiple plots in a for loop combined with variable cell arrays

1 次查看(过去 30 天)
Okay so i think my title sounds more difficult then it actually is.
So as a basic example: I have 2 Sets of Data, lets say y=x and y=2x, both range from 0 to 10. I want to plot both of them but i specificly want to look at x between 2 and 6. As i sometimes have more datasets all of this is in a for loop.
I Split each set of data into 3 pieces. 1. irrelevant range 0-2
2. relevant range 2-6
3. irrelevant range 6-10
All of this worked BUT now my problem: I try to plot them inside the loop like u see below with i beeing my loop index. But no matter the order there is always the second dataset of the first to plots missing. In the example below x_irrelevant2{2} and x_relevant{2} are missing and i dont know why.
plot(x_irrelevant2{i},y_irrelevant2{i},'color',[0.5 0.5 0.5],'Marker','.','linestyle','none')
plot(x_relevant{i},y_relevant{i},'color',c{i},'Marker','.','linestyle','none')
plot(x_irrelevant1{i},y_irrelevant1{i},'color',[0.5 0.5 0.5],'Marker','.','linestyle','none')

采纳的回答

Stephen23
Stephen23 2020-11-27
编辑:Stephen23 2020-11-27
By default every plot call deletes the contents of the figure before plotting the new data. So if you want to call plot multiple times and not remove any existing lines or markers, then you need to tell MATLAB:
plot(...) % first plot
hold('on') % <- you need this
plot(...) % other plots
hold('off') % afterwards
Read more:
  1 个评论
Patrick Petre
Patrick Petre 2020-11-27
oh thank you.. i actually had hold on after all of the plots but seems like i need one after every plot. thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by