Vectors must be the same length

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

Answers (1)

Benjamin
Benjamin 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!