How to effectively plot semi continuous graph

1 次查看(过去 30 天)
Dear Matlab Code The objective was to have a plot as below
At the moment, I am using a rather ineffecient approach, such as,
Xaxis = [273.5 275.5 277.5 279.5 281.5 283.5 303.5 305.5 307.5 315.5 317.5 319.5];
Yaxis = [0.61202 1.62647 1.37831 2.74613 2.24585 0.49887 0.61202 0.73511 2.2399 1.62647 1.99175 4.61222];
subplot(2,1,1);
plot (Xaxis (1,1:6), Yaxis (1,1:6), '--mo');
hold on
plot (Xaxis (1,7:9), Yaxis (1,7:9), '--mo');
hold on
plot (Xaxis (1,10:12), Yaxis (1,10:12), '--mo');
May I know any other smart alternative to the above line?
Thanks in advance for the time.

采纳的回答

Star Strider
Star Strider 2017-7-6
I cannot say this is better, but it is different, and does the vector splitting on its own:
Xaxis = [273.5 275.5 277.5 279.5 281.5 283.5 303.5 305.5 307.5 315.5 317.5 319.5];
Yaxis = [0.61202 1.62647 1.37831 2.74613 2.24585 0.49887 0.61202 0.73511 2.2399 1.62647 1.99175 4.61222];
Xsplit = diff([0 find(diff(Xaxis)>2) length(Xaxis)]); % Find Discontinuities & Create Lengths Vector
Xc = mat2cell(Xaxis, 1, Xsplit); % Split ‘Xaxis’
Yc = mat2cell(Yaxis, 1, Xsplit); % Split ‘Yaxis’
figure(1)
plot(Xc{1}, Yc{1}, '--mo', Xc{2}, Yc{2}, '--mo', Xc{3}, Yc{3}, '--mo')
  6 个评论
balandong
balandong 2017-7-7
Dear Star Thanks for the detailed explanation. Really appreciate it.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by