# Error using plot Vectors must be the same length.

1 view (last 30 days)
Cada vez que corró este código obtengo este error Error using plot Vectors must be the same length., he intentado de todo pero no sé cuál es el problema.
close all
clear
clc
%%
L=1.2;
l=0:0.175:0.8;
W=200;
a=1;
w=W/a^2*l;
DX=0.0001;
%%
for l = 0.1:0.175:0.8
w=(W/((a^2)*l))*a;
B_y=((w*a)*(L/2)*0.4)/0.8;
A_y=((w*a)*(L/2))-B_y;
end
%%
for l = 0:0.175:0.8
x1= 0:DX:(((0.8-l)/2)+0.2);
n1= length(x1);
x2= (((0.8-l)/2)+0.2):DX:(0.6+(l/2));
n2= length(x2);
x3= (0.6+(l/2)):DX:(1.2);
n3= length(x3);
V1= A_y;
M1= A_y*(x1-0.2);
V2=A_y-(w*a*(x2-0.6));
M2=A_y*(x2-0.2)-(w*a((x2-0.6).^2)/2);
V3= A_y+B_y-(w*a*(x3-0.6));
M3= A_y*(x3-0.2)+B_y*(x3-1)-(w*a*((x3-0.6).^2)/2);
%%grafica son los limites
x= [x1, x2, x3];
V= [V1, V2, V3];
M= [M1, M2, M3];
%% graficar
figure(1)
plot(x,V)
title("CORTANTE")
xlabel("x(m)")
ylabel("V(N)")
grid on
figure(2)
plot(x,M)
title("MOMENTO")
xlabel("x(m)")
ylabel("M(N*m)")
grid on
end

KSSV on 2 Nov 2020
You need to rethink on your code...you have messed up at lot of places...What exactly you are trying to plot?
Esteban Rodriguez Daza on 2 Nov 2020
I need to plot the V vs m, that's my force vs distance, but I have 5 different plots because I have a variable with 5 different inputs or values. But, I don't what it's happening with my code, and what i messed up.
I would appreciate it if you would help me to know what I did wrong and how I could correct it.

Kiran Felix Robert on 5 Nov 2020
Hi Esteban,
The plot function works only when the input arguments X and Y have identical dimensions.
In your code, when you try to plot ‘x’ and ‘V’ in line 39, the size of x is [1,12002] and size of V is [1,6002], this throws an error.
To plot x vs M, remove the line 39 to line 45, this will work as ‘x’ has same size as ‘M’
Check your code for variables to have identical dimensions before plotting.
Kiran Felix Robert