# Vector error when using plot function

9 views (last 30 days)
Bharkha Mistry on 4 Dec 2020
Answered: VBBV on 25 Sep 2021
Hello, I am trying to plot the following and keep receiving an eror on plot((V1:0.1:Vmax),nmax) stating:
Error using plot - Vectors must be the same length.
Error in maybeFinal (line 285)
plot((V1:0:Vmax),nmax)
this is my code, would someone be able to help me please :
nmax = 3.8;
nmin = -1.5;
V1=((nmax*2*W)/(C_Lmax*rho1*S))^(1/2);
V2=((nmin*2*W)/(C_Lmax*rho1*S))^(1/2);
Vpos=[0:V1];
Vneg=[0:V2];
q = 30.42;
n1=(C_Lmax*rho1*S*Vpos.^2)/(2*W);
n2=(C_Lmax*rho1*S*Vneg.^2)/(2*W);
Vmax=((2*q)/rho1)^(1/2);
% Plotting Vn diagram %
plot(Vpos, n1)
hold on
plot(Vneg, n2)
hold on
plot((V1:0.1:Vmax),nmax)
hold on
plot([V2:.1:Vmax],nmin)
hold on
plot(Vmax,[nmin:.01:nmax])
% Labeling Vn Diagram %
gtext ('Positive Stall Limit')
gtext ('Negative Stall Limit')
gtext ('Positive Structural Limit')
gtext ('Negative Structural Limit')
xlabel ('Calibrated Airspeed, ft/sec')

Star Strider on 4 Dec 2020
This:
plot((V1:0:Vmax),nmax)
creates an empty vector for the independent variable vector, since there is an increment (or step) of 0.
I suspect that you intended to replicate this plot call:
plot((V1:0.1:Vmax),nmax)
##### 2 CommentsShowHide 1 older comment
Star Strider on 4 Dec 2020
My pleasure!
Try something like this:
Vvct = linspace(V1, Vmax, numel(nmax));
This assumes ‘nmax’ is a vector.
If it is a matrix, choose the dimension (rows=1 or columns=2) that you want as the independent variable, and change it to:
Vvct = linspace(V1, Vmax, size(nmax,1));
for example, with this plotting across the columns as a function of the rows. The plot function automatically uses the other dimension as the independent variable, if they are different. With a square matrix, it may be necessary to transpose it to get the correct plot.

VBBV on 25 Sep 2021
nmax = 3.8;
nmin = 1.5;
W = 150;
C_Lmax = 1.6;
rho1 = 1.225;
S = 2;
V1=((nmax*2*W)/(C_Lmax*rho1*S))^(1/2);
V2=-round(((nmin*2*W)/(C_Lmax*rho1*S))^(1/2));
Vpos=[0:V1];
Vneg=[V2:0];
q = 30.42;
n1=(C_Lmax*rho1*S*Vpos.^2)/(2*W);
n2=(C_Lmax*rho1*S*Vneg.^2)/(2*W);
Vmax=((2*q)/rho1)^(1/2)
Vmax = 7.0474
% Plotting Vn diagram %
figure(1)
plot(Vpos, n1, Vneg,n2); figure(2)
plot(V1:-0.1:Vmax)
hold on
plot(V2:0.1:Vmax,'r-')
hold on
plot([nmin:.01:nmax],Vmax,'ro','MarkerSize',8)
% Labeling Vn Diagram %
% gtext ('Positive Stall Limit')
% gtext ('Negative Stall Limit')
% gtext ('Positive Structural Limit')
% gtext ('Negative Structural Limit')
xlabel ('Calibrated Airspeed, ft/sec') May be this is what you are looking for ...