Tutorial by Examples

The following MATLAB script shows how to define and call a basic function: myFun.m: function [out1] = myFun(arg0, arg1) out1 = arg0 + arg1; end terminal: >> res = myFun(10, 20) res = 30
The following MATLAB script shows how to return multiple outputs in a single function: myFun.m: function [out1, out2, out3] = myFun(arg0, arg1) out1 = arg0 + arg1; out2 = arg0 * arg1; out3 = arg0 - arg1; end terminal: >> [res1, res2, res3] = myFun(...
In the body of a function nargin and nargout indicate respectively the actual number of input and output supplied in the call. We can for example control the execution of a function based on the number of provided input. myVector.m: function [res] = myVector(a, b, c) % Roughly emulates the c...

Page 1 of 1