MATLAB Programming Tips - The MathWorks - #29

/ 66


catalogue search
P. 01
P. 02
P. 03
P. 04
P. 05
P. 06
P. 07
P. 08
P. 09
P. 10
P. 11
P. 12
P. 13
P. 14
P. 15
P. 16
P. 17
P. 18
P. 19
P. 20
P. 21
P. 22
P. 23
P. 24
P. 25
P. 26
P. 27
P. 28
P. 29
P. 30
P. 31
P. 32
P. 33
P. 34
P. 35
P. 36
P. 37
P. 38
P. 39
P. 40
P. 41
P. 42
P. 43
P. 44
P. 45
P. 46
P. 47
P. 48
P. 49
P. 50


See other catalogues for The MathWorks

Text version of the page
Program Development
For more information: see in the Programming Fundamentals documentation.
General Coding Practices
A few suggested programming practices:
• Use descriptive function and variable names to make your code easier to understand.
• OrdersubfunctionsalphabeticallyinanM-filetomakethemeasiertofind.
• Precede each subfunction with a block of help text describing what that subfunction does. This not only explains the subfunctions, but also helps to visually separate them.
• Do not extend lines of code beyond the 80th column. Otherwise, it will be hard to read when you print it out.
• Use full Handle Graphics® property and value names. Abbreviated names are often allowed, but can make your code unreadable. They also could be incompatible in future releases of MATLAB.
Naming a Function Uniquely
To avoid choosing a name for a new function that might conflict with a name already in use, check for any occurrences of the name using this command:
which -all functionname For more information: See the which function reference page.
TheImportanceofComments
Be sure to document your programs well to make it easier for you or someone else to maintain them. Add comments generously, explaining each major section and any smaller segments ofcode that are not obvious. You can add a block of comments as shown here.
%_____________________________________________
% This function computes the ... <and so on>
%_____________________________________________
1-21

pageCatalog pdf di En 2012-06-22-01