Graphics Programs Reference
In-Depth Information
% Do the valleys:
ind = find(z>0);
zplot = z;
zplot(ind) = zeros(size(ind));
axis tight
Now try this in the matlab window:
matlab has executed the instructions in mfile1.m just as if you had
typed them in. The lines beginning with the percent sign % are ignored
by matlab so they can be used to put comments in your code. Blank
lines can be used to improve readability.
Any variables created by a script m-file are available in the command
window after the m-file completes running:
>> clear
>> whos
>> mfile1
>> whos
Bytes Class
12352 double array
19208 double array
19208 double array
Grand total is 6346 elements using 50768 bytes
These variables are said to exist in the matlab workspace . Scripts can
also operate on variables that already exist in the workspace.
You can type the name of a script file within another script file. For
example you could create another file called mfile2 that contains the
text line mfile1 ; the contents of mfile1 will then be executed at that
point within mfile2 .
8.2 Functions
Functions are m-files that can be used to extend the matlab language.
Functions can accept input arguments and produce output arguments.
Many of matlab's own commands are implemented as m-files; try typ-
ing type mean to see how matlab calculates the mean. Functions use
Search WWH ::

Custom Search