Help creating a function
7 views (last 30 days)
Show older comments
Kevin Edlebeck
on 4 Feb 2018
Commented: Star Strider
on 4 Feb 2018
I've done the tutorials and searched the forums and I cannot find an answer to my question. I want to define a series of functions that I can call on using the function and its associated values. Like this:
F(x,y,z)=x*y*z -this is a dumbed down version of what I need F(1,2,3)= 6 -this is the result I'm hoping to get so that I can use the function for various scenarios.
That way I can define a particular case z=f(1,2,3) z=6
0 Comments
Accepted Answer
Star Strider
on 4 Feb 2018
3 Comments
Star Strider
on 4 Feb 2018
I cannot go into detail about how MATLAB handles functions work because I have not inquired into it. (I once knew how FORTRAN created the stack interfaces and such, since I had to write assembly language functions and had to know how to make them compatible with the FORTRAN compiler.)
When you create a function, you give it a list of inputs (arguments) to use within the function to calculate the result you want. See Function Basics (link) for details. They are designed to work essentially as algebraic functions work.
Note that anonymous functions will use variables from your user workspace unless you declare those variables with the same names as your workspace variables to be function arguments. Then it uses the variables passed to it as arguments instead.
Functions work with arrays if you write them to do so. See the documentation on Array vs. Matrix Operations (link) and Vectorization (link) for details.
I am not avoiding answering your questions about functions. The MATLAB documentation discusses them much more clearly and efficiently than I can, so I direct you to it.
More Answers (0)
See Also
Categories
Find more on Fortran with 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!