MATLAB For Dummies, 2nd Edition
Book image
Explore Book Buy On Amazon

The Current Folder window really does show the current MATLAB folder listed in the Address field. You don’t see anything because the current folder has no files or folders to display. However, you can add files and folders as needed to store your MATLAB data.

Permanently changing the default folder

The default folder is the one that MATLAB uses when it starts. Setting a default folder saves you time because you don’t have to remember to change the current folder setting every time you want to work. If you have your default folder set to the location from which you work most of the time, you can usually get right to work.

If you want to permanently change the default folder so that you see the same folder every time you start MATLAB, you must use the userpath() command. Even though this might seem like a really advanced technique, it isn’t hard. Simply type userpath(‘C:MATLAB') in the Command window and press Enter. You need to change the path to wherever you placed the downloadable source.

To see what the default path is for yourself, type userpath and press Enter. MATLAB displays the current default folder.

Creating a new folder

Organizing the files that you create is important so that you can find them quickly when needed. To add a folder to the Current Folder window, right-click any clear area in the window and choose New Folder from the context menu. MATLAB creates the new folder for you. Type the name you want to use for the new folder and press Enter.

Running a saved script

You can run any script by right-clicking its entry in the Current Folder window and choosing Run from the context menu. When you run a script, you see the script name in the Command window, the output in the Workspace window, and the actual command in the Command History window.

Saving the current workspace to disk

Sometimes you might want to save your workspace to protect work in progress. The work may not be ready to turn into a script, but you want to save it before quitting for the day or simply to ensure that any useful work isn’t corrupted by errors you make later.

To save your workspace, click Save Workspace in the Variable group of the Toolstrip’s Home tab. You see a Save to MAT-file dialog box that looks similar to the Select File for Save As dialog box. Type a filename for your workspace, such as FirstWorkspace.mat, and click Save to save it.

Workspaces use a .mat extension, while scripts have a .m extension. Make sure that you don’t confuse the two extensions. In addition, workspaces and scripts use different icons so that you can easily tell them apart in the Current Folder window.

About This Article

This article is from the book:

About the book authors:

Jim Sizemore is professor of physics and engineering at Tyler Junior College. For over 25 years, Sizemore has worked in the semiconductor and software industries as a process engineer, device physicist, and software developer. John Paul Mueller has written more than 100 books and more than 600 articles on topics ranging from functional programming techniques to application development using C++.

This article can be found in the category: