This is an old revision of the document!
====== Math 445 lecture 3: scripts ====== topics <code> Matlab scripting plot, semilogy, semilogx, loglog xlabel, ylabel, title, legend linestyles load, save what, pwd </code> ===== Matlab scripting ===== 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> % plot cos(x) and sin(x) over 0 < x < 2pi x = linspace(0, 2*pi, 100); plot(x, cos(x), 'b-', x, sin(x), 'r-'); xlabel('x'); legend('cos x', 'sin x'); </code> If you download this file and place it in your current working directory (folder), Matlab will be able to find it and execute it. In my case, Matlab is running in the directory ''/home/gibson/math445''. Here <code matlab> >> pwd % print working directory ans = /home/gibson/math445 >> what % print names of Matlab scripts in working directory MATLAB Code files in the current folder /home/gibson/math445 plotsincos >> plotsincos % execute the plotsincos script </code>