Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Error using plot Vectors must be the same lengths.

Subject: Error using plot Vectors must be the same lengths.

From: Chris

Date: 10 Mar, 2013 14:57:08

Message: 1 of 3

So I am somewhat new to matlab and am getting this error when i run this code: Error using plot Vectors must be the same lengths. I believe everything in my code is correct just it wont run. PLEASE HELP!

clf
close all

s=0:0.1:6;
L=8.4;
P=800;
B=[P*cosd(20); -P*sind(20); 0];

for i=1:length(s)
x(i)=(L^2-49+(14*s(i)))/(2*L);
y(i)=sqrt(x(i)^2-s(i)^2);
A1=[ 1, 0, (((7-s(i))/(L-x(i)))-(s(i)/x(i)))];
A2=[ 0, 1, ((y(i)/(L-x(i)))+(y(i)/x(i)))];
A3=[ 5.1, 3.5, ((7*y(i))/x(i))];
A=[ A1; A2; A3];
T(:,i)=A\B;
end

figure
plot(s,T(1,:),s,T(2,:),s,T(3,:),'LineWidth',1)
xlabel('s[Meters]','FontSize',16)
ylabel('Tension[Newtons]','FontSize',16)
title('Tension in the rope as a function of s','FontSize',16)

Subject: Error using plot Vectors must be the same lengths.

From: Kristin

Date: 19 Mar, 2013 23:16:05

Message: 2 of 3

"Chris " <ccimine00@ccny.cuny.edu> wrote in message <khi704$cp6$1@newscl01ah.mathworks.com>...
> So I am somewhat new to matlab and am getting this error when i run this code: Error using plot Vectors must be the same lengths. I believe everything in my code is correct just it wont run. PLEASE HELP!
>
> clf
> close all
>
> s=0:0.1:6;
> L=8.4;
> P=800;
> B=[P*cosd(20); -P*sind(20); 0];
>
> for i=1:length(s)
> x(i)=(L^2-49+(14*s(i)))/(2*L);
> y(i)=sqrt(x(i)^2-s(i)^2);
> A1=[ 1, 0, (((7-s(i))/(L-x(i)))-(s(i)/x(i)))];
> A2=[ 0, 1, ((y(i)/(L-x(i)))+(y(i)/x(i)))];
> A3=[ 5.1, 3.5, ((7*y(i))/x(i))];
> A=[ A1; A2; A3];
> T(:,i)=A\B;
> end
>
> figure
> plot(s,T(1,:),s,T(2,:),s,T(3,:),'LineWidth',1)
> xlabel('s[Meters]','FontSize',16)
> ylabel('Tension[Newtons]','FontSize',16)
> title('Tension in the rope as a function of s','FontSize',16)

>> help plot

    PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by
    the (X,Y,S) triples, where the X's and Y's are vectors or matrices
    and the S's are strings.

Subject: Error using plot Vectors must be the same lengths.

From: TideMan

Date: 20 Mar, 2013 01:51:18

Message: 3 of 3

On Monday, March 11, 2013 3:57:08 AM UTC+13, Chris wrote:
> So I am somewhat new to matlab and am getting this error when i run this code: Error using plot Vectors must be the same lengths. I believe everything in my code is correct just it wont run. PLEASE HELP!
>
>
>
> clf
>
> close all
>
>
>
> s=0:0.1:6;
>
> L=8.4;
>
> P=800;
>
> B=[P*cosd(20); -P*sind(20); 0];
>
>
>
> for i=1:length(s)
>
> x(i)=(L^2-49+(14*s(i)))/(2*L);
>
> y(i)=sqrt(x(i)^2-s(i)^2);
>
> A1=[ 1, 0, (((7-s(i))/(L-x(i)))-(s(i)/x(i)))];
>
> A2=[ 0, 1, ((y(i)/(L-x(i)))+(y(i)/x(i)))];
>
> A3=[ 5.1, 3.5, ((7*y(i))/x(i))];
>
> A=[ A1; A2; A3];
>
> T(:,i)=A\B;
>
> end
>
>
>
> figure
>
> plot(s,T(1,:),s,T(2,:),s,T(3,:),'LineWidth',1)
>
> xlabel('s[Meters]','FontSize',16)
>
> ylabel('Tension[Newtons]','FontSize',16)
>
> title('Tension in the rope as a function of s','FontSize',16)

Every Matlab user has this problem from time to time.
You must learn to figure it out yourself.
The first step is to check the sizes:
[size(s) size(T)]
if the answer is not:
1 61 3 61
then you must find out why it is not.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us