Having trouble using a function
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
Hi everyone. I am trying to create a function that computes an output 'T' using two inputs, 'h,Ve'. However, whenever i try to run the code i am hit by the error 'Not enough input arguments'. The code is as follows:
function[T] = Function_T
%Calculating for trim
%h = length of horizontal semi axis of ellipse
%Ve= length of vertical semi axis of ellipse
T= (1/(atan*(h/Ve)))-2/pi;
end
I then try to use this code by defining input values for h and ve and then running the function:
h=0.8;
Ve=0.9;
T=Function_T;
But still i get the same error message. Anyone know what i'm doing wrong? Cheers in advance.
1 个评论
John Harris
2018-3-26
In the first line, your function doesn't require any inputs. Try changing your first line to:
T = Function_T(h,Ve)
回答(2 个)
Birdman
2018-3-26
Give input arguments to function. The function has a local workspace therefore it will not recognize the global variables:
function[T] = Function_T(h,Ve)
%Calculating for trim %h = length of horizontal semi axis of ellipse %Ve= length of vertical semi axis of ellipse
T= (1/(atan*(h/Ve)))-2/pi;
end
and
h=0.8;
Ve=0.9;
T=Function_T(h,Ve);
0 个评论
Star Strider
2018-3-26
You need to define it with input arguments in order to use it with them. Unlike Anonymous Functions it will not pick up variables from your workspace. You also need to remove the ‘*’ from the atan call.
function [T] = Function_T(h,Ve)
%Calculating for trim
%h = length of horizontal semi axis of ellipse
%Ve= length of vertical semi axis of ellipse
T= (1/(atan(h/Ve)))-2/pi;
end
h = 0.8;
Ve = 0.9;
T = Function_T(h,Ve)
T =
739.5731e-003
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!