Akzeptierte Antwort

Adam Danz
Adam Danz am 28 Aug. 2020
Bearbeitet: Adam Danz am 31 Aug. 2020

1 Stimme

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 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by