Table of Contents
Overview
The workspace in MATLAB holds all the variables that exist in your current session. To see, inspect, and interact with these variables without typing commands every time, MATLAB provides two closely related tools in the desktop environment: the Workspace Browser and the Variable Editor, often referred to as the Variable Inspector. In this chapter you will focus on what these tools look like, how to open them, and how to use them to understand and explore your data.
The Workspace Browser
The Workspace Browser is the panel that shows a list of variables currently in memory. It usually appears as a panel labeled Workspace in the MATLAB desktop. If you do not see it, you can show it from the Home tab by choosing Layout and then enabling Workspace, or by using the Desktop menu and selecting Workspace.
In the Workspace Browser, each row corresponds to one variable. The typical columns show the name of the variable, its size, its type, and sometimes additional information such as complexity for real or complex values, and class for objects. For instance, if you create a variable A = rand(3,4); and a scalar x = 5;, the Workspace Browser will show A with size 3x4 and x with size 1x1.
You can sort the variables by clicking the column headers. For example, clicking the Name column orders variables alphabetically, and clicking the Size column groups variables with similar dimensions. This is useful when your workspace contains many variables and you want to quickly find a particular one or see all variables of a certain shape.
You can rename a variable directly in the Workspace Browser by slowly double clicking its name and typing a new one. MATLAB updates the name in the workspace as if you had assigned the value to a new variable and cleared the old name. Be careful with renaming, because any script that still refers to the old variable name will not see the new variable.
From the Workspace Browser you can also delete variables. You can select one or more variables using the mouse and press the Delete key, or right click and choose Delete. This has the same effect as using the clear command on those variable names. Removing large variables can free memory and keep your workspace tidy.
Opening Variables from the Workspace
A key feature of the Workspace Browser is that it lets you open variables for detailed viewing. When you double click on a variable in the Workspace Browser, MATLAB opens it in the Variable Editor. The Variable Editor window shows the contents of that variable in a spreadsheet style table, where each cell corresponds to an element of the variable.
You can also right click a variable in the Workspace Browser to see more options. These usually include Open in Variable Editor, Plot, and sometimes other actions depending on the variable type. Choosing Open in Variable Editor gives the same result as double clicking the variable name.
If you select several variables and right click, MATLAB may offer plotting or comparison options. For simple exploration you will mainly use double click to open or close individual variables.
The Variable Editor as a Variable Inspector
The Variable Editor is the main tool for inspecting variable contents visually. It appears as a separate window or a tabbed panel, usually with the variable name as the tab title. When you open a numeric matrix, the Variable Editor shows rows and columns, with row indices on the left and column indices at the top. Values appear in the cells as you would see in a spreadsheet.
For a small matrix such as A = magic(4);, you can see all elements at once. For larger matrices, scroll bars appear so you can move through rows and columns. You can change the column width, and you can use the toolbar at the top of the Variable Editor to adjust display format, such as the number of decimal places.
The Variable Editor supports many data types, not only numeric arrays. For character arrays and string arrays it shows each character or string element. For logical arrays it displays values such as true and false. For tables, structures, and cell arrays it shows their internal layout with column or field labels. Although details of those container types are covered elsewhere, the important point here is that the Variable Editor adapts its display to make those types easier to inspect.
For scalars and very small arrays, the Variable Editor view is still useful because it lets you confirm values at a glance. For example, if you calculate stats.mean in a later chapter, opening it in the Variable Editor will confirm that it is a single number or a row vector, and you can see the exact value printed with a consistent numeric format.
Editing Values in the Variable Editor
One major convenience of the Variable Editor is that you can change variable values directly by typing in the cells. When you click on an element in the table the cell becomes editable and you can enter a new value, then press Enter to apply the change. MATLAB immediately updates the variable in the workspace, so any subsequent commands that use that variable will see the new value.
For instance, if an array A contains a wrongly entered element 999 at position $(2,3)$ and you open A in the Variable Editor, you can click on row 2, column 3 and replace 999 with the correct number. This is often quicker than constructing a command such as A(2,3) = 5; in the Command Window when you are experimenting or cleaning up.
You can also create new values beyond the current size of an array by typing into cells that lie outside its present bounds. For example, if A is currently 2x2 and you edit cell at row 3, column 1, MATLAB will expand A so that it contains row 3. Expansion rules and implications are discussed elsewhere, but here it is useful to know that the Variable Editor can cause arrays to grow if you type into new cells.
The Variable Editor supports undo for recent edits through its toolbar or standard keyboard shortcuts, which helps when you accidentally overwrite a value. However, once you close MATLAB or clear a variable, changes are permanent unless you saved a copy. It is often a good idea to keep track of major edits and consider using scripts to reproduce important changes.
Viewing Properties and Information
In the Variable Editor window you can access additional information about the variable through its toolbar and menus. There is usually a section that allows you to change how numbers are displayed, such as fixed decimal, scientific notation, or short and long formats. This does not change the underlying data, only the way it appears.
For certain types like tables or structures, the editor shows column or field names at the top. Clicking these headers can sort the rows by that column if sorting is supported. You might also see icons that indicate that a particular element contains nested data, such as a cell that holds another array. Double clicking such a cell can open the nested content in a new tab of the Variable Editor, giving a layered inspection view.
The Variable Editor title bar typically shows the variable name and sometimes its size and type. If you resize the window, MATLAB adjusts the table so that you see as many rows and columns as possible. The status bar can indicate the current cell coordinates or describe certain actions.
Inspecting Different Variable Types
The Workspace Browser and Variable Editor work together to help you handle a range of variable types. For numeric and logical arrays the Variable Editor looks like a typical grid of numbers or booleans. For character arrays it shows each character, which can be useful for seeing line breaks or spaces.
String arrays appear with one string per cell, often with quotes, so you can distinguish between a single string and a character array. For cell arrays each cell can contain data of its own. The Variable Editor shows the cell contents in a summarized form such as {1x4 double} or {'text'}. Double clicking a cell can open its contents in a new editor tab.
Structure arrays are shown with one row per structure element and one column per field. Each cell in that table represents the field content for that structure element. Again, double clicking can reveal more detail. The exact behavior for these container types will be explored when you study them in their own chapters, but you can already use the Variable Editor to browse their contents in an intuitive way.
Using Context Menus and Quick Actions
Right clicking on a variable in the Workspace Browser opens a context menu. Besides Open and Delete, you might see options like Copy which copies the variable to the clipboard in a textual form, or Save As which lets you save a particular variable to a file. There can be plotting options such as Plot or Bar depending on whether MATLAB can interpret the variable content as numeric data suitable for plotting.
Inside the Variable Editor, right clicking on cells gives you another context menu. This can include options to cut, copy, paste, clear selected cells, or insert and delete rows and columns. Some of these options depend on the data type. For simple numeric matrices you can, for example, select a block of cells, copy them, and paste them into another part of the same variable or into another variable that is open in the editor.
You can also select ranges of cells and press the Delete key to set them to zero, empty, or an appropriate default for the data type. For logical arrays, deleting might set values to false. The editor usually shows what will happen before you confirm the operation.
Searching and Navigating Large Variables
When you work with larger arrays or tall tables, navigating by scrolling can become slow. The Variable Editor provides some tools to help. There is usually a search box that lets you type a value or text and find matching entries within the current variable. For numeric arrays this often searches for exact matches, while for text data it looks for substrings.
Navigation keys like Page Up, Page Down, Home, and End help you move around quickly. You can also enter a specific row or column index in some interfaces to jump to that part of the data. If the variable is extremely large, MATLAB may show only part of it at first, and loading more of it can take time. In that case, you can often work with a subset or use commands in the Command Window to create a smaller view.
Because the Variable Editor shows actual contents, it can help identify patterns, missing values, or outliers visually. For example, in a column of numbers you might notice an obviously incorrect value just by scanning the column. The ability to scroll and search makes this kind of quick inspection practical.
Interactions with Scripts and the Command Window
Any change you make in the Variable Editor affects the workspace immediately. If you run a script and then open a variable in the editor, what you see is the result of that script at the moment it finished. If you then modify the variable in the editor and run more commands in the Command Window, those commands will see your modified values.
If you rerun the script, it will recreate variables according to its code, which might overwrite the edits you just made. This interaction is important when you are experimenting. The Workspace Browser helps you keep track of which variables exist at any moment, while the Variable Editor helps you understand and adjust their contents. For reproducible work, you typically move any important edits back into your scripts as explicit commands.
You can also create simple variables directly from the Workspace Browser or Variable Editor without using the Command Window. For example, you might copy a column of data from a spreadsheet program and paste it directly into an empty variable in the Variable Editor. MATLAB creates the variable for you. This kind of manual data entry should be used carefully, because it can be harder to reproduce, but it is useful for quick tests.
Summary of Key Ideas
Remember these points about the Workspace Browser and Variable Editor:
They show you which variables exist, along with their size and type, without typing commands.
You can open variables from the Workspace Browser by double clicking to inspect them in the Variable Editor.
The Variable Editor lets you view and edit variable contents in a spreadsheet style interface, and changes take effect immediately in the workspace.
Different data types appear in different ways, but you can usually drill down by double clicking cells that contain nested data.
Right click context menus in both the Workspace Browser and Variable Editor provide quick actions such as open, delete, copy, and plot.
Edits in the Variable Editor are convenient for exploration, but for reproducible work you should encode important changes in scripts.