FUNCTION REFERENCE
function
Define a function.
Define a function.
Syntax
function name, statements, endSyntax
function y = name(x), statements, endSyntax
function [y, z] = name(a, b), statements, endPut the definition in a .mr or .m file in the Current Folder, named like the function. Helper functions may follow in the same file. A function has its own workspace and can call up to 32 levels deep. Inside it, nargin and nargout give the number of inputs and outputs of the call.
A file twice.mr with these lines:
function y = twice(x)
y = 2 * x;
endthen twice(4) returns 8. Help for such a function prints its leading comment lines.
Differences from MATLAB: Not checked against MATLAB yet. A file may hold only function definitions, so a definition cannot be typed in the command line together with other statements.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.