Useful Tips


MATLAB editor

MATLAB has a built-in editor for creating scripts and function files (known as m-files, because the file names must end in .m). To access the editor, you can do one of the following four things:

  1. From the File menu, select New, then Blank M-File or Function M-File. You will need to name the file when you save it.
  2. In the Current Directory pane, under the icon that looks like a gear, there is the option to open a new file, and you can choose between a function m-file and a blank m-file. The file will pop up in the Current Directory pane, and you will need to name it, then double-click on it to open it in the editor.
  3. You can find the New file icon in the icon bar at the top of the MATLAB window. You will need to name the file when you save it.
  4. You can use the command edit filename.m, where filename is whatever name you want the file to have.

Whichever method you choose, remember to save all changes to the file before trying to run the file!

MATLAB help function

The help command brings up a basic list of features about the function or script you are interested in. For example:

help sin
 SIN    Sine of argument in radians.
    SIN(X) is the sine of the elements of X.
    See also ASIN, SIND.

    Overloaded methods:

    Reference page in Help browser
       doc sin

If you don't really know what is the name of the function you are looking for, you can just type help -- it will bring up a huge list of topics and you can just click on the topic links that you think is helpful.

MATLAB help window

Or, if you prefer the more conventional graphical interface, you can click on the characteristic blue box Help, or type


to bring up Matlab's help and demo window. You can then search for terms in the "Help Navigator" panel.

Semicolon operator

By default, MATLAB prints the outcome of each command typed in the command line, like the following:

x = 1
x =


Sometimes, the commands generate a huge list of numbers (think about a vector with 100 elements!) and mess up the command window. The semicolon operator (;) can be used to suppress command-line echo:

x = 1;

Repeating commands

You can repeat a command without retyping it by using the up arrow. Keep hitting the up arrow until you get to the command you want. Or, you can type the start of the command, and hitting the up arrow will go back through all the commands that start with what you typed.

Scientific notation

To write numbers in scientific notation, use 'e':

y = 1e9
y =


rather than writing out 1x10^9.