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
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
Birdman 2018 年 3 月 26 日

0 投票

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);
Star Strider
Star Strider 2018 年 3 月 26 日

0 投票

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

この質問は閉じられています。

質問済み:

2018 年 3 月 26 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by