Lesson 1.3

MATLAB Environment

Summary

  • Learn the main components of the MATLAB Environment.
  • Understand how to use the MATLAB software to write code.
  • Use the interface to find and set the current working location of MATLAB.

MATLAB Environment Windows and Parts

The MATLAB Environment is all the windows, sub-windows, and parts that are part of the MATLAB program (note, both the software interface and the actual computer language are called MATLAB). By default, the components of the MATLAB Environment are laid out as shown in Figure 1. Note that we are referencing MATLAB versions R2015a and above in this lesson. Previous versions have some similarities, but R2012a and before are significantly different visually (no ribbon navigation). However, the basic parts like the Editor and Command Window are fundamentally the same throughout the different versions.


Figure 1: The major windows and section of the default setup of the MATLAB Environment.

The following sections of this lesson will review the individual and major parts of the MATLAB Environment seen above in Figure 1. You can refer back to this figure and/or open MATLAB to see physically where the different pieces are as you progress through this lesson. It is essential for a beginner to understand each component and its function in order to write MATLAB code.

Navigation Ribbon

As with most modern programs the navigation ribbon is a way to help users find, understand, and use MATLAB software features efficiently and directly. The navigation ribbon has different tabs that lump similar software functionality together. Within a ribbon tab you can find different groups. An example of this can be found in the “Home” tab that includes the “File” group, which includes various functions and options for working with MATLAB files such as “New”, “Open”, or “Compare”.


Figure 2: The navigation ribbon in the MATLAB Environment.

The most common location on the ribbon that you will use is “Editor” tab. Under the Editor tab, you can create a new m-file (a file for your code) and run that file. You can also see the “Save” button in the Editor tab, which will save your m-file. Note that running the m-file automatically saves your m-file. One way or the other, it is a good idea to save your file often.

The “Publish” tab contains functions that can be used to present your code and MATLAB work in a nice and neat way. This functionality of the “Publish” ribbon tab can be reviewed in Appendix A (LINK TO LESSON).

The “Plots” and “Apps” tabs contain modules and functions that are shortcuts to a specific piece of MATLAB code. Although the shortcuts can be convenient and efficient to a particular workflow, they are not essential to this course: we are just mentioning them informatively here. You may want to play around with these ribbon tabs and explore their functionality later in the course.

Working Folder Location

The working folder location bar shows the current directory that MATLAB is referencing (see Figure 3). This is the computer folder from which your code will run. If the working directory is different than the location of your code, MATLAB will prompt to change the working folder location (shown in Figure 4). The working folder location bar works in conjunction with the current folder window, which is explained in the following section.


Figure 3: The working folder display in MATLAB.

Figure 4 shows the prompt you will get if the m-file you are trying to run is not in MATLAB’s current folder or on one of it’s (directory) paths. “Change Folder” means: make the folder that contains this m-file the “current folder”. In order words, set the folder as the current project folder. “Add to Path” means add the folder location of the m-file you are trying to run to MATLAB’s paths. A path is a more permanent directory that MATLAB will always look in when trying to find a program or function you are running/calling. Simply put, choose “Change Folder” most of the time/if you don’t know. Neither option will “break” anything, and both should work fine for our purposes.


Figure 4: MATLAB’s user prompt to change the current working folder.

Current Folder

The current folder MATLAB Environment subwindow, shown by default on the right hand side of the window, shows you what files are in your working folder location (see Figure 5). This includes all subfolders and any type of files that are inside the working directory.


Figure 5: Current folder contents window in MATLAB.

Command Window

The Command Window has a number of different uses in MATLAB. Generally, it acts as an output window and a temporary/quick coding environment. We will cover this window in depth in a following lesson (LINK TO LESSON).


Figure 6: MATLAB’s Command Window.

Editor Window

While the Command Window can act as a temporary coding environment, the MATLAB Editor window is used to write out lines code, or a script, that can be executed all at the same time. You can write an entire code sequence before running it. We will cover this window more in depth in the following lesson on the m-file (LINK TO LESSON). This window should not be confused with the Editor tab. They are related, but not the same thing as you can see in MATLAB.


Figure 7: The Editor window (m-file editor) used to write and save a complete code.

Workspace

While programming, you will actively define variables to store data and values for later use. Such memory storage can range from storing text and numbers to storing large vectors and matrices. The workspace window (Figure 8) displays all variables that are currently defined and stored into memory. It can be helpful in that it shows different properties of that particular variable such as its type (“Class”), it’s matrix dimensions (“Size”), or the amount of memory used to store it (“Bytes”). You can even see quick facts about numerical data like the mean of the data.


Figure 8: The workspace window that is used to monitor any MATLAB data currently loaded into memory.

Status Bar

The status bar indicates the active status of the MATLAB program. Most of the time, there will be nothing important to display here. However, one particularly useful message is when MATLAB tells you it is “Busy” or “Waiting for an input”. “Busy” generally means it is working on computations in the background from the last code you asked it to run. “Waiting for an input” refers to MATLAB waiting for a user input that you specified in your program (more on this in Inputs and Outputs (LINK TO LESSON)).


Figure 9: The status bar that notifies the user of important MATLAB status messages.

Next Lesson

In the next lesson, we will cover how to change the MATLAB windows layout and how to change basic user preferences.