Hi there! I'm just starting with matlab, so this question may seem a little too easy.
1 view (last 30 days)
Show older comments
Margherita De Flammineis
on 18 Oct 2018
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
0 Comments
Accepted Answer
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).
0 Comments
More Answers (1)
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!