how to input a matrix into a function HELPPP
15 views (last 30 days)
Show older comments
i am confued with a question on how to create a function that accpets data maxtrix as an input. The matrix has 3 coloumns that record specfici data however i am unsure how you can input a matrix into your function.
0 Comments
Accepted Answer
Bjorn Gustavsson
on 6 Mar 2020
It sounds as if your new to matlab. If so welcome. Good advice then is to point you to introduction tutorials etc.
If you have your n x 3 matrix something like this:
A = [1 2 3;pi sqrt(2) exp(1)];
Then you simply send that variable to the function:
B = sin(A);
C = log(A);
and so on. Your function must have the ability to handle the matrix, but that is for the function to deal with. If you dont know how to make the function vetorized you might have to loop over the elements in the appropriate way, for that one tends to use the function size to figure out how many elements there are to loop over.
HTH
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!