I have a function that returns three values [A,B,C]=ABC(x)
.
Is it possible to define a function A(x)
in an elegant way such that returns the first value of ABC(x)
, B(x)
for the second value, etc.?
Thanks
I have a function that returns three values [A,B,C]=ABC(x)
.
Is it possible to define a function A(x)
in an elegant way such that returns the first value of ABC(x)
, B(x)
for the second value, etc.?
Thanks
Not completely clear whether you really mean that ABC
returns a vector, or that it returns three values (each of which might be any object). If you really mean "vector" with three elements, [A B C]
. then you could do:
function a = A(x)
temp = ABC(x);
a = temp(1);
As you wrote your function ([A,B,C]=ABC(x)
) it does not return a vector per say, it returns 3 values.
If you call your function like this
a = ABC(x)
a
would be equal to A
.
EDIT :
function b = B(x)
[~, b, ~] = ABC(x)
end
You could include a 2nd input argument if it is acceptable to you. You could use varargin
to accept variable number of input arguments.
function outValue=ABC(varargin);
if nargin==0
error('Need at least one argument');
elseif nargin==1
%obtain result
outValue=result;
elseif nargin==2
%obtain result
outValue=result(index);
else
error('Function accepts maximum of 2 arguments');
end
end