1. MATLAB Info Home
  2. Teaching
  3. Citrix
  4. Publishing
  5. Publishing 2
  6. Emailing
  7. Getting Started
  8. Plotting
  9. My Homepage
Getting Started in MATLAB

Most of the .m files in the H-drive are what are called SCRIPT files. They are lines of commands just as if I'd typed them in line by line in the command window. Script files are very convenient to use, as to get something just a little different, you just change the file and don't have to re-type everything in (and helpful when things aren't working to fix them). It is best to create the script file through the editor window in MATLAB and save it in the directory of your choice. See the Citrix info page for more info on the directories.

Running the script file: First, your ``Current Directory'' should be the directory that you saved your files. This is found at the top, towards the right on the MATLAB screen. You can run it two ways:

  1. From the editor window: have the script file open, and either hit F5 or select ``Run'' (or ``Save and Run'') in the Debug menu at the top. This can only be done with script files that require no additional input from the user.
  2. From the command window: If your file is filename.m, type filename and press enter at the command prompt.

You can put comments in the script files by starting each comment line with %

One thing to pay close attention to is how to do component-wise computations on vectors (and matrices). This is especially important for plotting, as to plot something as simple as y = (2x^2 + 5)/x, we create a vector of x-values, and then we want to compute a vector of the corresponding y-values. To multiply, divide, and take powers component-wise (addition, subtraction and scalar multiplication is automatically so), we put a ``.'' before the operation symbol. For the graph of y = (2x^2 + 5)/x for 0.5 <= x <= 2, we'd do this by doing something like the following (the comments are only for your benefit):

x=linspace(0.5,2);            % creates a vector of 100 numbers equally spaced
                              % between -2 and 2
y= (2*x.^2 + 5)./x;           % computes (2x^2+5)/x component-wise
plot(x,y)                     % plots the points formed by x, y
                              % vectors
title('Basic Plot Example')   % puts a title in the plot

NOTICE THE ``;'' AT THE END OF THE LINES FOR CREATING x AND y!

Instructor: Dr. Lisa Oberbroeckling
Office: 312 Knott Hall
Phone: 410-617-2516
Email: loberbro "at" loyola "dot" edu