MATLAB Answers

how can i pass a vector to a function?

768 views (last 30 days)
anu vru
anu vru on 8 Feb 2018
Commented: Ziyu Xu on 23 Oct 2019
i have a function which has 2 variables each of these variables are a vector. how do i pass vector inputs to the function???

  0 Comments

Sign in to comment.

Accepted Answer

Birdman
Birdman on 8 Feb 2018
function z=f(x,y)
z=x.^2+y.^2;
end
From command line, type
x=[1;2];y=[3;4]
z=f(x,y)
and the result would be
[10;20]

  1 Comment

Ziyu Xu
Ziyu Xu on 23 Oct 2019
OMG, you just saved my life!

Sign in to comment.

More Answers (0)

Sign in to answer this question.