
BeginwithExistingCode
BeginwithExistingCode
In this section...
“Create M-Files from Command Window and History” on page 6-3
“Use Existing M-Files and Examples” on page 6-3
Create M-Files from Command Window and History
Before you begin writing MATLAB code in a blank file, consider s tar tin g with
existing resources for the code, and then use the MATLAB Editor/Debugger to
modify the code.
In many cases, you create and run MATLAB statements in the Command
Window, modify those statements to your satisfaction, and then create
an M-file that includes the statements. To facilitate this process, in the
Command History, select the MATLAB statements you want to include in the
M-file. Right-click and select Create M-File. The Editor/Debugger opens
a new file that includes the statements you selected fro m the Command
History. You can also copy the statements from the Command History and
paste them into an e xisting M-file.
Use Existing M-Files and Examples
If you can find existing M-files that accomplish what you want to do, copy and
use the code in your own M -file, assuming you have legal permission to do so.
Follow ing are some resources you can use.
MATLAB and Toolbox M-Files
Yo u can access and reuse the code in most MATLAB and toolbox functions
that have a
.m file extension. You cannot use MATLAB and toolbox functions
that are built-in. They are e fficient but their code is not accessible.
If there is a MATLAB function that is similar to what you need to do and it is
not built-in, open the file in the Editor/Debugger and use it as a basis for your
file. Be sure to save the file using a different name and in a directory that is
not in
matlabroot/toolbox. S ee “Saving Files” on page 6-62 for details.
6-3
Kommentare zu diesen Handbüchern