Script M-files

Exercise

 

> Open a new script M-file by clicking on New Script while in Home tab. A new window will be opened. It has three tabs: Editor, Publish and View. To create, save, run, and edit your M-file you need to stay in the Editor tab.

> From now on every M-file should start with comment headers that include your name and student ID as well as a description of the purpose of the code as follows:

% Practical 2 Graphing exercise

% <Add your name, student ID and today’s date here>

> Add in the commands:

clear all

x=2^3

> Save your M-file, for example, as prac2e1.m in your preferred directory and make sure that the Current Folder in MATLAB is set to the same location.

> Enter command prac2e1 (or whatever name you saved your M-file as) in the Command Window. It should execute your M-file code. Please, note absence of the file extension .m

wink Coding tip: When you create M-files, try typing only the first couple of lines of code and check that the M-file works.

wink Coding tip: You can also click on the Run mode or press F5 key while having MATLAB M-file Editor window open. Your M-file will be saved and executed. To see the output you will need to return to the Command Window.