


Matlab functions must begin with the keyword "function".% Additional lines of first comment are reported by "help" % First comment line is reported by "lookfor" The general syntax of a Matlab function is as follows:įunction = functionName( inarg1, inarg2.As a consequence, functions have mechanisms for passing arguments into the functions, and for returning the results.Variables defined and used in a function do not affect the regular Matlab workspace. Functions, however, define a separate ( local ) scope.Any variables created get added to the workspace, and may replace other variables that were already defined there with the same names. Ordinary script files have the problem that they run in the scope of the command window.Both are plain ASCII files containing Matlab commands, with ".m" file extensions.Matlab function files are very similar to Matlab script files, with a few important differences.

Etter, "Introduction to MATLAB, Second Edition", Section 3.6. Hahn & Valentine, "Essential MATLAB for Engineers and Scientists", Fourth Edition, Chapter 10 up to section 10.3.3.
