How do I solve this error: 'Error using alpha. Too many output arguments.' ? It comes up when I try to create a user-defined function for the input: 'de_trim'.
15 views (last 30 days)
Show older comments
The code is supposed to take the user input 'de_trim' and calculate if creates a stall condition for the plane. None of the output arguments are actually based on 'de_trim', it really just comes into play for with the loop at the end.
As of right now the code as a function works. But when I try to display 2 figures it gives me the error message: "Error using alpha. Too many output arguments." 'alpha' is an vector of 11 entries, and is used as the x-axis in a 'plot' command. It's paired up with 'Cm' which is also 11 units long.
If I hide the top line that defines the code as a function the figures get generated without any issue. 'alpha' and 'Cm' come from a load file which define the variables:
alpha= [-16, -8, -6, -4, -2, 0, 2, 4, 8, 9, 10], and
Cm=[.339, .219, .181, .144, .109, .075, .043, .013, -.048, -.066, -.084].
CL= [-1.2860, -0.6159,-0.4200,-0.2235,-0.0313,0.1609, 0.3557,0.5533,0.9495,1.0380,1.1170].
function [CL0,CLa,Cm0,Cma]= Dixon_Jordan_M1(de_trim)
load('assignment1.mat')
figure
plot(alpha,Cm) %y=-.016*x+.08 (from best fit tool)
grid on
title('Cm v AoA')
xlabel('AoA ')
ylabel('Cm')
text(1.25,.350,'y=-.016*x+.08')
figure
plot(alpha,CL) %y=.094*x+.17 (from best fit tool)
grid on
title('CL v AoA')
xlabel('AoA ')
ylabel('CL')
text(-11.5,.35,'y=.094*x+.17')
%figure
%plot(CL,Cm)
%grid on
%title('Cm v CL')
%xlabel('CL ')
%ylabel('Cm')
%from a linear best-fit of the above figure (Cm v Cl): y=-.17*x+.11;
Cmcl=-.17;
SMs=-Cmcl;
yint=.11;
CLtrim=-yint/Cmcl; %CLtrim=.647
X_NP=(SMs*cbar)+X_CG; %corrected X_NP; returns a value of 2.669
%Values from CL v AoA and Cm v AoA (linear best fit tool)
CLa=.094;
CL0=.17;
Cma=-.016;
Cm0=.08;
%values derived from user input, de_trim
CLinput= ((de_trim)+(yint/-.03))*(-.03/SMs);
%trim angle of attack
Alpha_Trim=(CLinput-CL0)/CLa; %returns value of 5.07 with CLtrim=.647
%%%%%Stall Condition%%%%%
CLmax=1.5;
de_trimM=(yint/.03)+(SMs/-.03)*CLmax;
fprintf('The slope of CL v AoA, CLa is %.3f , the intercept CL0 is %.3f.\nThe slope of Cm v AoA, Cma %.3f , the intercept Cm0 is %.3f.\n',CLa,CL0,Cma,Cm0)
fprintf('\nThe neutral point, X_NP, was found to be %.3f ft.\n',X_NP)
fprintf('\nWhen considering a non-linear best curve for Cm v AoA, polynomial n=10, Cm0 becomes %.3f.\n',yint)
if de_trim == de_trimM;
fprintf('\nFlying at CLmax, at sea level Vstall is 95.17 ft/s')
elseif de_trim < de_trimM;
fprintf('\nde_trim does not conflict with stall conditons, the resulting velocity is %.f ft/s\n',Vinput)
else de_trim > de_trimM;
fprintf('\nThe value %.2f for de_trim, requires coefficeint of lift greater than max.\nThe max value for de_trim was calculated to be %f\n',de_trim, de_trimM)
end
0 Comments
Accepted Answer
Walter Roberson
on 5 Oct 2016
filevals = load('assignment1.mat');
alpha = filevals.alpha;
Cm = filevals.Cm;
CL = filevals.CL;
The JIT changed a couple of releases ago.
Previously if you load() without any outputs and so "poof" a variable into existence and the variable had the same name as a function, then the variable was used -- except in the case where there is an end statement matching the function statement, in which case it was defined that the name-as-a-function would win out.
Now (R2015b? R2016a?) if you poof a variable into existence like that inside a function, and the variable name matches the name of a function, then the name-as-a-function wins out.
The long-term cure is to not poof variables into existence: recode to have load() output a struct and pull the values out of the struct.
The short-term cure would be to assign something to the variable before using the load() to poof the variable into existence:
alpha = 0;
load('assignment1.mat');
would result in alpha being treated as a variable in the code.
0 Comments
More Answers (0)
See Also
Categories
Find more on Digital Filter Analysis 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!