You are on page 1of 13

Creating, Saving and Executing a Script File

• A script file is a user created file with a sequence of matlab commands in


it. The file must be saved with a ‘.m’ extension to its name, thereby,
making it an M-file. A script file is executed by typing its name (without
the ‘.m’ extension at the command prompt.
What do we learn here
• How to create, write and save a script file.
• How to execute the script file in MATLAB.
• How to use the built-in MATLAB editor on a PC.
• How to open, edit and save a file
• In which directory your file is saved in.
How to open the MATLAB editor

Click the above encircled icon


MATLAB editor will be opened
• Type the following lines:
• After writing these lines we have to save this file
Modify the script file aks.m to draw a circle
of arbitrary radius r as follows:
• Include the following command in the script file before the first
executable line to ask the user to input(r) on the screen :
r=input(‘Enter the radius of the circle: ‘)
• Modify the x and y coordinate calculations appropriately .
• Save and execute the file. When asked, enter a value for the radius
and press return.
Modify the script file aks.m to show the center of
the circle on the plot, too. Show the center point
with a ‘+’.
𝑥 = 𝑥𝑐 +𝑟 cos 𝜃

𝑦 =𝑦 𝑐 +𝑟 sin 𝜃

You might also like