MATLAB Software

MATLAB Interface

MATLAB opens showing multiple interface panes. In general, you need to see the Command Window and the Workspace. Other visible panes may include the Command History and Current Folder. If you want to change the visible panes, click on the Layout button from the HOME tab and select panes to add or hide.

Image shows the default layout for MATLAB Desktop. There is a left column with the current folder (showing files), a center column showing the Command Window (where you enter commands), and the right column in the base Workspace (where you can see any variables you've entered into MATLAB)

MATLAB Online is similar, and you can customize the same way as the Desktop app.

Get Help in MATLAB

  • Use the help function to display help text for a specified MATLAB function.
  • Use the doc function to open the MATLAB Help Browser.

Set Current Folder

MATLAB looks in the current folder to find your script and function files. You need to set the current folder to match the location of the script or function that you want to run. You should get in the habit of saving your files to your Purdue Career Account drive, which is backed up by Purdue servers, or to MATLAB Drive, which is backed up by MathWorks. Using a basic folder structure to organize your files by assignment, exam, and projects is a good engineering habit and will help you when you need to navigate in MATLAB to the correct folder.

Shows a call-out of the navigation toolbar and current folder path

Tutorials and help documentation from MathWorks.

Variable Names

MATLAB variable names in this course must meet both the MATLAB requirements and the course programming standards. The definition of a built-in function in this course is any command that came pre-loaded in MATLAB.

Rule for Naming VariablesExample
Must start with a letterCorrect: time1
Incorrect: 1time
Can only contain letters, numbers, and/or underscoresCorrect: travel_time
Incorrect: travel-time
Should be descriptive of the dataDescriptive: travel_time
Inappropriate: t
Are case sensitiveDIST is the not the same variable as dist
Cannot be MATLAB keywordsExamples: break, if
Type iskeyword in the Command Window to view a list of MATLAB keywords
Do not use built-in function namesExamples: clc, sqrt, min, max
MATLAB will allow you to create a variable name with the same name as a built-in function. Avoid doing this because doing so is bag programming and may cause unexpected behavior when you execute your code.
Useful MATLAB commands to help discover existing variable and function names
Command SyntaxFunctionality
whoList the existing variables in the current workspace
whosList the existing variable with their formats in the current workspace
help elfunView a list of elementary math functions
help possible_varnameSee if there is help information for a built-in function. The function exists if this command returns help documentation for the requested function name
exist possible_varnameCheck if variable names or functions are defined. Example returns:
0 if possible_varname does not exist
1 if it is in the workspace
5 if it is a built-in function
possible_varnameEnter the desired variable name into the Command Window. This returns an error if MATLAB does not recognize the name as a variable, function, etc.