채택된 답변

Adam Danz
Adam Danz 2020년 8월 28일
편집: Adam Danz 2020년 8월 31일

1 개 추천

One way to plot 3 lines that share x-coordinates is to plot the lines individually. That's shown in the first subplot below.
A second way is to create 1 vector of x and y coordinates where NaN values are used to separate and disconnect the lines. That's shown in the second subplot below.
The very strange and difficult to interpret x-tick marks that repeat is thankfully not an option in Matlab but you can change the x-tick labels. In the two demos below, the actual x ticks range from 0 to 20, monotonically. Then I change the labels.
x0 = 0 : .5 : 10;
x1 = x0 + 5;
x2 = x1 + 5;
y = x0*10;
clf
subplot(1,2,1)
hold on
plot(x0,y, 'r-')
plot(x1,y, 'r-')
plot(x2,y, 'r-')
grid on
set(gca, 'XTick', 0:2:20, 'XTickLabels', [0 5 0 5 0 5 0 5 10 15 20])
subplot(1,2,2)
x = [x0, nan, x1, nan, x2, nan];
y = repmat([y,nan], 1, 3);
plot(x,y, 'r')
grid on
set(gca, 'XTick', 0:2:20, 'XTickLabels', [0 5 0 5 0 5 0 5 10 15 20])

댓글 수: 2

Andra Mantighian
Andra Mantighian 2020년 9월 3일
Thank you!
Eliza Haque
Eliza Haque 2023년 8월 19일
Were you able to draw the graph? I need to plot something similar but I am not getting it.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2020년 8월 28일

댓글:

2023년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by