Matlab and Octave Programming for STEM Applications · LibreTexts
0%
Contents
Text
Size
From LibreTexts, under CC BY-NC-SA 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.
2.11: Script Documentation
Opening the book…
Every script should provide documentation, which is a comment that explains what the script does and what its requirements are.
For example, I might put something like this at the beginning of fibonacci1.m:
% Computes a numerical approximation of the nth Fibonacci number.
% Precondition: you must assign a value to n before running this script.
% Postcondition: the result is stored in ans.
A precondition is something that must be true when the script starts in order for it to work correctly. A postcondition is something that will be true when the script completes.
If there is a comment at the beginning of a script, MATLAB assumes it’s the documentation for the script. So if you type help fibonacci1, you get the contents of the comment (without the percent signs).
>> help fibonacci1
Computes a numerical approximation of the nth Fibonacci number.
Precondition: you must assign a value to n before running this script.
Postcondition: the result is stored in ans.
That way, scripts that you write behave just like predefined scripts. You can even use the doc command to see your comment in the Help Window.