Help creating a function
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2018년 2월 4일
댓글 수: 3
Star Strider
2018년 2월 4일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!