Hi there! I'm just starting with matlab, so this question may seem a little too easy.

1 view (last 30 days)
Hi there! I'm just starting with matlab, so this question may seem a little too easy. Can I return a vector from a function? If yes, what syntax should I use? Thanks a lot

Accepted Answer

Stephen23
Stephen23 on 18 Oct 2018
Edited: Stephen23 on 18 Oct 2018
"Can I return a vector from a function?"
Of course.
"If yes, what syntax should I use?"
Nothing special, exactly the same syntax is used for returning all types of variable from a function:
function X = myfun()
X = [1,2,3]; % a vector
end
and then try it yourself:
myfun()
Read the function help to know how to define functions (including any input and/or output arguments).

More Answers (1)

madhan ravi
madhan ravi on 18 Oct 2018
Edited: madhan ravi on 18 Oct 2018
x=1:10;
Vector = myfunction(x);
function Vector = myfunction(x)
disp('x = ')
disp(x)
end
Like this? But I don’t see the purpose though.

Categories

Find more on MATLAB 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!