Graphics Programs Reference
In-Depth Information
cross
c
= cross(
a
,
b
)
The function
cross
computes the cross product:
c
=
a
×
b
, where vectors
a
and
b
must beoflength 3.
1.8
Writing and Running Programs
MATLAB hastwo windows available for typing program lines: the
command window
and the
editor/debugger
. The command windowis always in the interactive mode, so
that any statemententeredinto the windowis immediatelyprocessed. The interactive
mode is agood way to experiment with the language and try out programming ideas.
MATLAB opens the editor windowwhenanew M-file iscreated,oranexisting file
isopened. The editor windowis used to type and save programs(called
script files
in
MATLAB) and functions. Onecouldalso use a texteditor to enterprogram lines, but
the MATLAB editor hasMATLAB-specificfeatures, such as color coding andautomatic
indentation,that make workeasier. Before aprogram or function can beexecuted, it
must besavedas a MATLAB M-file (recall that these files have the
.m
extension).A
program can be run by invoking the
run
command from the editor's
debug
menu.
Whenafunctioniscalled for the first time during a program run, it iscompiled
into P-code(pseudo-code) to speedupexecutioninsubsequentcalls to the function.
Onecanalso create the P-codeofa functionand save itondisk by issuing the command
pcode
function name
MATLAB will then load the P-code(which has the
.p
extension) into the memory
rather than the text file.
The variables created during a MATLAB sessionaresavedinthe MATLAB
workspace
until theyare cleared. Listing of the saved variables can be displayedbythe
command
who
. If greaterdetail about the variables is required,type
whos
. Variables
can be cleared from the workspace with the command
clear
ab
...
which clears the variables
a
,
b
,
...
. If the list of variables isomitted, all variables are
cleared.
Search WWH ::
Custom Search