Home

How to Save a Formula or Command as a Script in MATLAB

|
|  Updated:  
2016-03-27 09:31:27
|   From The Book:  
MATLAB For Dummies
Explore Book
Buy On Amazon

After you create a formula or command that you want to use to perform a number of calculations in MATLAB, be sure to save it to disk. Of course, you can save anything that you want to disk. The following steps help you save any formula or command that you want to disk so that you can review it later:

Choose a location to save the formula or command in the Address field.

Right-click the formula or command that you want to save in the Command History window.

Choose Create Script from the context menu.

Choose Create Script from the context menu.

You see the Editor window. The script is currently untitled, so you see the script name as Untitled*.

If you want to select multiple commands to place in a script, you can choose them by clicking on the first command, and then using Ctrl+Click to select any additional commands. Each time you Ctrl+Click on a command, MATLAB highlights its entry. The commands will appear in the script file in the same order in which they appear in the Command History window.

Click Save on the Editor tab.

Click Save on the Editor tab.

You see the Select File for Save As dialog box.

In the left pane, highlight the location you want to use to save the file.

You will see a File Name field.

Type a name for the script in the File Name field.

The example uses FirstScript.m. However, when you save your own scripts, you should use a name that will help you remember the content of the file. Descriptive names are easy to remember and make precisely locating the script you want much easier later.

MATLAB filenames can contain only letters and numbers. You can’t use spaces in a MATLAB filename. However, you can use the underscore in place of a space.

Click Save.

MATLAB saves the script for you so that you can reuse it later. The title bar changes to show the script name and its location on disk.

Close the Editor window.

Close the Editor window.

The Current Folder window displays the folder and script file.

About This Article

This article is from the book: 

About the book author:

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.