In MATLAB, we have command window, in which we type command and press enter to execute. If you want to write command in MATLAB you have to write all commands in sequence and have to press enter after every line. So, it is not convenient way to write a program in MATLAB.
MATLAB provides a better way to execute set of commands, by creating a script file. In script file you have to list all commands in it, save it and execute file. When the file runs, commands are executed in the order as they are listed in the file. If needed, the commands in file can be changed and then file can be saved and run again with updated commands.
- Script file is sequence of commands, can be called program.
- If script file contains command that generates an output, output will be displayed in command window
- Script files are also called M-files because files are saved with .m extension
Create a script file in MATLAB
Script files are created in Debugger window.
- In File menu, select New and then select Script
- Script file can be opened with shortcut key Ctrl + N
Follow tutorial for creating and executing files.