programming tips, OZE, matlab instrukcje

[ Pobierz całość w formacie PDF ]
The Language of Technical Computing
Programming Tips
Version 6
How to Contact The MathWorks:
Technical support
Product enhancement suggestions
Bug reports
Documentation error reports
Order status, license renewals, passcodes
Sales, pricing, and general information
The MathWorks, Inc.
3 Apple Hill Drive
Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
MATLAB Programming Tips
(Excerpted from the MATLAB documentation for Programming and Data Types)
COPYRIGHT 1984 - 2002 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or repro-
duced in any form without prior written consent from The MathWorks, Inc
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by
or for the federal government of the United States. By accepting delivery of the Program, the government
hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR
Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part
252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain
to the government’s use and disclosure of the Program and Documentation, and shall supersede any
conflicting contractual terms or conditions. If this license fails to meet the government’s minimum needs or
is inconsistent in any respect with federal procurement law, the government agrees to return the Program
and Documentation, unused, to MathWorks.
MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and
TargetBox is a trademark of The MathWorks, Inc.
Other product or brand names are trademarks or registered trademarks of their respective holders.
Printing History: July 2002
Online only
First printing for MATLAB 6.5 (Release 13)
MATLAB Programming Tips
This chapter is a categorized compilation of tips for the MATLAB
programmer. Each item is
relatively brief to help you to browse through them and find information that is useful. Many of the
tips include a link to specific MATLAB documentation that gives you more complete coverage of the
topic. You can find information on the following topics:
“Command and Function Syntax” on
page 3
Syntax, command shortcuts, command recall, etc.
“Help” on page 6
Getting help on MATLAB functions and your own
“Development Environment” on page 11 Useful features in the development environment
“M-File Functions” on page 13
M-file structure, getting information about a function
“Function Arguments” on page 16
Various ways to pass arguments, useful functions
“Program Development” on page 18
Suggestions for creating and modifying program code
“Debugging” on page 21
Using the debugging environment and commands
“Variables” on page 25
Variable names, global and persistent variables
“Strings” on page 28
String concatenation, string conversion, etc.
“Evaluating Expressions” on page 31
Use of
, short-circuiting logical expressions, etc.
“MATLAB Path” on page 33
Precedence rules, making file changes visible to
MATLAB, etc.
“Program Control” on page 37
Using program control statements like
“Save and Load” on page 41
Saving MATLAB data to a file, loading it back in
“Files and Filenames” on page 44
Naming M-files, passing filenames, etc.
“Input/Output” on page 47
Reading and writing various types of files
“Managing Memory” on page 50
What you can do to use less memory in your MATLAB
“Optimizing for Speed” on page 56
Acceleration, vectorizing, preallocation, and other ways
you can get better performance
MATLAB Programming Tips
“Starting MATLAB” on page 60
Getting MATLAB to start up faster
“Operating System Compatibility” on
page 61
Interacting with the operating system
“Demos” on page 63
Learning about the demos supplied with MATLAB
“For More Information” on page 64
Other valuable resources for information
Command and Function Syntax
Command and Function Syntax
This section covers the following topics:

“Syntax Help”

“Command and Function Syntaxes”

“Command Line Continuation”

“Completing Commands Using the Tab Key”

“Recalling Commands”

“Clearing Commands”

“Suppressing Output to the Screen”
Syntax Help
For help about the general syntax of MATLAB functions and commands, type
help syntax
Command and Function Syntaxes
You can enter MATLAB commands using either a
It is important to learn the restrictions and interpretation rules for both.
functionname arg1 arg2 arg3 % Command syntax
functionname('arg1','arg2','arg3') % Function syntax
For more information:
See “Calling Functions” in the MATLAB
“Programming and Data Types” documentation
Command Line Continuation
You can continue most statements to one or more additional lines by
terminating each incomplete line with an ellipsis
. Breaking down a
statement into a number of lines can sometimes result in a clearer
programming style.
sprintf ('Example %d shows a command coded on %d lines.\n', ...
example_number, ...
   [ Pobierz całość w formacie PDF ]