Octave Programming Tutorial/Writing functions
From Wikibooks, the open-content textbooks collection
In Octave function definitions follow the following scheme:
function [return value 1, return value 2, etc] = name( arg1, arg2, etc )
body
endfunction
As an example consider the factorial function, which takes exactly one argument and returns one integer value.
function result = factorial( n )
if( n == 0 )
result = 1;
return;
else
result = prod( 1:n );
endif
endfunction
Return to the Octave Programming tutorial index