Is there a way to disconnect lines between data points while utilizing the plot function?

조회 수: 60 (최근 30일)
Let's say I have the following lines of code;
x = [1;2;3;4;5;6;7;8;6];
y = [10;20;30;40;50;60;70;80;30];
plot(x,y,'-o');
When executed, I get a simple 2D line plot where all 9 of the Y values are plotted and connected by a solid line.
Is there a way to disconnect the line between the 8th and 9th data point while maintaining it for the first 8?
  댓글 수: 1
Ihaveaquest
Ihaveaquest 2022년 8월 17일
plot([30 30.1 30.1 30.2 30.2 30.3 30.3 30.4 30.4 30.5 30.5 30.6 30.6 30.7], [-7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7.5 -7.5 -8 -8], 'k','LineStyle','--', 'linewidth',3, 'HandleVisibility','off')
i am using this methos but I would like to erase the drop lines. ideas how to do that

댓글을 달려면 로그인하십시오.

채택된 답변

sixwwwwww
sixwwwwww 2013년 10월 22일
편집: sixwwwwww 2013년 10월 22일
Dear Brad, you can do it the following way:
x = [1;2;3;4;5;6;7;8;9];
y = [10;20;30;40;50;60;70;80;90];
plot(x(1:end - 1),y(1:end - 1),'-o'); hold on
plot(x(end), y(end), 'o')
xlim([x(1) x(end)+x(1)]), ylim([y(1) y(end)+y(1)])
I hope it helps. Good luck!
  댓글 수: 2
Karla Fabiola Ramirez Martinez
Karla Fabiola Ramirez Martinez 2020년 2월 22일
God bless you however you are, i really had a good fight troubling with ploting points and after a lot of search none of those helped me, but this one saved me

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Kindig
Matt Kindig 2013년 10월 22일
Another way is to insert a NaN between the dis-connected points, such as:
x = [1;2;3;4;5;6;7;8;6];
y = [10;20;30;40;50;60;70;80;30];
x = [ x(1:8), NaN, x(9:end)];
y = [ y(1:8), NaN, y(9:end)];
plot(x,y,'-o');
Matlab won't plot a NaN, so the effect is to break up your lines.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by