Illustration of script:
For illustration, we will now generate a script known as script1.m which calculates area of the circle. It assigns a value for the radius, and then computes the area based on that radius.
In this text, the scripts will be showed in a box with the name on top.
In a Command Window, the contents of the script can be displayed, and then the script can be executed. The type command represents the contents of the file named script1.m (note that the .m is not involved):
>> type script1
radius = 5
area = pi * (radius^2)
There are 2 ways to view a script once it has been written: either open the Editor Window to view it, or use the type command as shown to display it in the Command Window.
To actually run or execute the script, the file name is entered at the prompt (one more time, without the .m). Whenever executed, the results of the two assignment statements are displayed, as the output was not suppressed for either of the statement.
The script has been once executed; you may find that you want to make changes to it. To edit an existing file, there are various methods to open it. The easiest methods are:
- Click File, then Open, and then click the name of the file.
- Click the present Directory tab, and then double-click the name of the file.