Vectors must be the same length

6 views (last 30 days)
Martin Svensson
Martin Svensson on 2 Dec 2021
Answered: Voss on 2 Dec 2021
my code says "vectors must be the same length" really new to matlab.
load("lnu (1).mat")
axis equal;
hold on
s=[1 0;0 -1];
t=[cos(2*pi/3) -sin(2*pi/3);sin(2*pi/3) cos(2*pi/3)];
axis equal;

Answers (1)

Voss on 2 Dec 2021
plot takes vectors in pairs of arguments, like plot(x1,y1,x2,y2, ...)
The second call to plot in your code uses three numeric arguments, so plot's going to treat xy as a vector of x-values and a as a vector of corresponding y-values, but I suspect that they don't have the same number of elements. (Can't say for sure because I don't have the data, but this is a guess based on the error message.)
Try splitting the variable xy into its x and y parts and send it as two consecutive arguments in both calls to plot, e.g., plot(xy(:,1),xy(:,2)) or plot(xy(1,:),xy(2,:)), depending on how xy is arranged (again, can't say for sure without the data.)

Community Treasure Hunt

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

Start Hunting!

Translated by