====== Differences ====== This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
gibson:teaching:spring-2018:math445:lecture:scripts [2018/01/30 02:37] gibson created |
gibson:teaching:spring-2018:math445:lecture:scripts [2018/01/30 02:43] (current) gibson [Matlab scripting] |
||
---|---|---|---|
Line 15: | Line 15: | ||
A Matlab **script** is simply a list of Matlab commands in a plain-text (ASCII) file with a ''.m'' filename extension. If you **call** or **execute** the script by its name at the Matlab prompt //without the .m extension//, Matlab will read the file and execute the commands sequentially. For example, here is a Matlab script that will make a plot of $\sin x$ and $\cos x$, complete with labeled axes and a legend. | A Matlab **script** is simply a list of Matlab commands in a plain-text (ASCII) file with a ''.m'' filename extension. If you **call** or **execute** the script by its name at the Matlab prompt //without the .m extension//, Matlab will read the file and execute the commands sequentially. For example, here is a Matlab script that will make a plot of $\sin x$ and $\cos x$, complete with labeled axes and a legend. | ||
- | <code matlab | plotsincos.m> | + | <code matlab plotsincos.m> |
% plot cos(x) and sin(x) over 0 < x < 2pi | % plot cos(x) and sin(x) over 0 < x < 2pi | ||
x = linspace(0, 2*pi, 100); | x = linspace(0, 2*pi, 100); | ||
Line 31: | Line 31: | ||
<code matlab> | <code matlab> | ||
>> pwd % print working directory | >> pwd % print working directory | ||
- | |||
ans = | ans = | ||
- | |||
/home/gibson/math445 | /home/gibson/math445 | ||
Line 40: | Line 38: | ||
MATLAB Code files in the current folder /home/gibson/math445 | MATLAB Code files in the current folder /home/gibson/math445 | ||
+ | plotsincos | ||
</code> | </code> | ||
- | When the script is run, Matlab opens a new figure window and draws the plot | + | You *run* a script by typing its name at the Matlab prompt (without the ''.m'' file extension). When the script is run, Matlab opens a new figure window and draws the plot |
<code matlab> | <code matlab> |