Vector error when using plot function

조회 수: 11 (최근 30일)
N/A
N/A 2020년 12월 4일
댓글: Star Strider 2020년 12월 4일
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')

답변 (1개)

Star Strider
Star Strider 2020년 12월 4일
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
N/A
N/A 2020년 12월 4일
Thank you!
I used the correction that you provided and still receive the same error.
Star Strider
Star Strider 2020년 12월 4일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by