Accepted Answer

Adam Danz
Adam Danz on 28 Aug 2020
Edited: Adam Danz on 31 Aug 2020
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 Comments

Were you able to draw the graph? I need to plot something similar but I am not getting it.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!