[beginner] How do you plot two vectors of diffrent length?
4 views (last 30 days)
How do you go about to plot two vectors of diffent lengths in Matlab? One of my homework assignments is to great a plot graph using these two vectors:
x1 = [1 2 3 4 5 6]
y1 = [3,5 4,8 7,1 9,1 10,5 13,2]
However, this seems impossible due to the nature of the plot function, where it demands vectors to be of same length. I tried plot(x1, y1) and that didn't work. We haven't gotten anymore information than this :(
Maybe the teacher inserted a comma when it should've been a decimal point inside vector y1? He's Swedish, so maybe that's why.
Dave B on 7 Sep 2021
Edited: Dave B on 7 Sep 2021
At some level the question is what you expect from the plot.
When I look at your y1 vector, I notice that it's got an odd arrangement of commas and spaces. I wondered if maybe it was intending to make a 2x6 or 6x2 matrix, which would make a lot of sense to plot against the numbers 1 to 6.
x1 = [1 2 3 4 5 6];
y1 = [3 5;4 8;7 1;9 1;10 5;13 2];
More generally, to answer the title, you can plot two different length vectors as follows:
y1 = rand(1,5);
y2 = randn(1,7);