three difference vectors and plots

1 visualizzazione (ultimi 30 giorni)
Junway
Junway il 17 Mar 2021
Commentato: Junway il 18 Mar 2021
I want to plot three difference vector in one figure.
this is sample data. I keep error "vectors must be the same length".
how should I change it?
x = [ 1, 2, 3, 4, 5]
x1 = [ 1.1, 2.2, 3.4, 4, 4.5]
x2 = [0.9, 1.9, 3, 3.9, 4.3]
y= [1, 2, 3, 4, 5];
y1=[2, 3, 4, 5, 6];
y2 = [1, 3, 6, 7, 8]
hold on
plot(x,y)
plot(x1,y1)
plot(x2,y2)
hold off

Risposte (1)

Steve Eddins
Steve Eddins il 18 Mar 2021
I have copy-pasted your code below, exactly as entered in your question. It runs and produces the plot with no error. I suggest that you double-check your code carefully. If you still get an error, then copy your code from MATLAB directly into a comment here, along with the exact text of any error message, so that we can take a look.
x = [ 1, 2, 3, 4, 5]
x = 1×5
1 2 3 4 5
x1 = [ 1.1, 2.2, 3.4, 4, 4.5]
x1 = 1×5
1.1000 2.2000 3.4000 4.0000 4.5000
x2 = [0.9, 1.9, 3, 3.9, 4.3]
x2 = 1×5
0.9000 1.9000 3.0000 3.9000 4.3000
y= [1, 2, 3, 4, 5];
y1=[2, 3, 4, 5, 6];
y2 = [1, 3, 6, 7, 8]
y2 = 1×5
1 3 6 7 8
hold on
plot(x,y)
plot(x1,y1)
plot(x2,y2)
hold off

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by