Matlab Class Home      Class Outline      Previous Task      Next Task      Main Class Page      Evaluation 1

Task 1.3 Detail: Use the MATLAB editor to create a command script.

Summary of new tools and commands.

We will use menus on the MATLAB page for this task.

Task: Start the script editor and create a new file (call it T1.m).

There are two ways to get MATLAB to do useful work for you. The most direct way is to type commands into the command window (typically, the large pane in the center of the MATLAB window). The MATLAB prompt is >> which indicates that MATLAB is waiting for a command.

A second way to control MATLAB is to create a file (a MATLAB script) which contains a series of commands to execute. This is the preferred way to interact with MATLAB because it keeps a record of the commands that you have used and it allows you to fix errors and re-run a series of commands without re-typing each one. You are almost guaranteed to make an error in the re-typing, so resist the temptation to "save time" by typing anything but the simplest commands into the command window.

There is a third way to control MATLAB's actions: though pull-down menus and various graphics user interfaces (GUI). I strongly discourage their use, for the same reason as above. It will be very hard for you to repeat work you are doing unless you remember all of the commands that you execute through menus.

A new script file is created with the "new" menu on the MATLAB window.

     new script

Choose the "script" option to get a new, untitled script. MATLAB scripts must have the ending (file extension) of ".m". A new window will open:

     matlab editor

Move the cursor to the upper left of the "untitled" pane and type the following commands. These should look familiar, but we will learn the details in the next task.

a=1
b=12
c=a+b
d=a/b
Use the "save" menu to save this file as "T1". The editor will automatically add ".m" to the name. If you save the file as "T1.m", then the editor will not add a second file extension.

File names can have letters, numbers, underscore and periods. Do not have spaces in the file names as this causes problems invoking the script. The file name must start with a letter.

The = character represents an "assignment operator", it does not express "equality". The statement c = a + b means "set the value of variable c to the sum of the values of variables a and b".

Use the "run" button on the editor window to execute the script. This also saves the current script to the file. This will cause some details to appear in the command window and information will appear in the Workspace pane on the main MATLAB window.

Notice that "T1" appeared in the command window followed by the variable names along with their values.

The file called "T1.m" has been saved in the default folder. We will control its location in the next task.

Matlab Class Home      Class Outline      Previous Task      Next Task      Main Class Page      Evaluation 1


email: J. Klinck