25-06-2012, 04:23 PM
Programming Tips
programming_tips.pdf (Size: 350.13 KB / Downloads: 41)
Introduction
This section is a categorized compilation of tips for the MATLAB®
programmer. Each item is relatively brief to help you browse through them
and find information that is useful. Many of the tips include a reference to
specific MATLAB documentation that gives you more complete coverage of
the topic. You can find information on the following topics:
For suggestions on how to improve the performance of your MATLAB
programs, and how to write programs that use memory more efficiently, see
Improving Performance and Memory Usage
Recalling Commands
Use any of the following methods to simplify recalling previous commands
to the screen:
• To recall an earlier command to the screen, press the up arrow key one or
more times, until you see the command you want. If you want to modify the
recalled command, you can edit its text before pressing Enter or Return
to execute it.
Paged Output
Before displaying a lengthy section of help text or code, put MATLAB into its
paged output mode by typing more on. This breaks up any ensuing display
into pages for easier viewing. Turn off paged output with more off.
Page through the displayed text using the space bar key. Or step through
line by line using Enter or Return. Discontinue the display by pressing
the Q key or Ctrl+C.
Passing Arguments in a Structure
Instead of requiring an additional argument for every value you want to pass
in a function call, you can package them in a MATLAB structure and pass the
structure. Make each input you want to pass a separate field in the structure
argument, using descriptive names for the fields.
Planning the Program
When planning how to write a program, take the problem you are trying
to solve and break it down into a series of smaller, independent tasks.
Implement each task as a separate function. Try to keep functions fairly
short, each having a single purpose.
Using Pseudo-Code
You may find it helpful to write the initial draft of your program in a
structured format using your own natural language. This pseudo-code is often
easier to think through, review, and modify than using a formal programming
language, yet it is easily translated into a programming language in the next
stage of development.