MatLab Tutorial
MatLab Tutorial
MatLab Tutorial
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
d. <strong>MatLab</strong> has a powerful graphics tool. x = linspace(0, 10, 100);y = sin(x);plot(x, y);plot(x, y, 'r-');z = cos(x);plot(x, y, 'r--', x, z, 'k.');There is much more about graphing in the other tutorial, but this will be all you need fortoday.----------------------------------------------------------------------------------------------------------------------------2. A program is a list of many commandsa. In <strong>MatLab</strong>, you write programs as text files and save them with a '.m' as the file extension.It is easiest to write these files with <strong>MatLab</strong>'s built in text editor, but in theory you coulduse MSWord or any other editor. Before you begin, create a place to keep your <strong>MatLab</strong>programs. - Create a folder on your desktop or thumb drive called something like'My<strong>MatLab</strong>' or whatever.- Now set the <strong>MatLab</strong>'s 'Current Folder' to your newly made folder byclicking on the ellipses button '…' in the middle of the control toolbaron the top-middle of screen.- Create a new m-file by clicking 'File > New > Blank M-File'- Save this (initially blank) file as 'PracticeScript.m' in your new folder.Note that <strong>MatLab</strong> program names being with a letter and end in '.m'.- Now copy and paste the following text into your m-file:close all; % Closes any current graphics windows.clear all; % Deletes any current variables.% Percent signs denote comments.x = linspace(-7, 7, 1000);y = sin(x) ./ x; % This is the famous sinc function.plot(x,y);- Press F5 on the keyboard to simultaneously save and run. This willbecome your favorite button when programming with <strong>MatLab</strong>.