Respuesta aceptada

Adam Danz
Adam Danz el 28 de Ag. de 2020
Editada: Adam Danz el 31 de Ag. de 2020

1 voto

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 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Ag. de 2020

Comentada:

el 19 de Ag. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by