Vector error when using plot function

6 views (last 30 days)
Bharkha Mistry
Bharkha Mistry on 4 Dec 2020
Commented: Star Strider on 4 Dec 2020
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')
ylabel ('Load Factor, n')

Answers (1)

Star Strider
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)
instead.
  2 Comments
Bharkha Mistry
Bharkha Mistry on 4 Dec 2020
Thank you!
I used the correction that you provided and still receive the same error.
Star Strider
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.

Sign in to comment.

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!