In previous chapters, you have got the way to enter commands from the Command prompt. MATLAB also allows you to write a series of commands into a file and execute the file as an entire unit, like writing a function and calling it as we write commands in various computer languages.

The M Files:-

MATLAB allows writing two shots of program files −

1. Scripts:-

Script files are program files with .m extension. In these files, you write a series of commands, which you want to execute together. Scripts don't accept inputs and don't return any outputs. They operate on data in the workspace.  

2. Functions:-

Functions files also are program files with .m extensionFunctions can accept inputs and return outputs. Internal variables are local to the function.
Creating and Running Script File:-
To create scripts files, you have to use a text editor. You can open the MATLAB editor using the command prompt, type edit in the command prompt. This will open the editor. The easiest way to create a file is, directly type edit and then the filename with .m extension 
Let us try to create an M-file using above steps:-
Step-1:-
 Let us open MATLAB software.
Step-2:-
Then go to command prompt and type edit than give a space and give the file name and end with .m extension and press ENTER.
Note:-
if you forget how to name any variable in MATLAB for creating an M-file just follow this link  https://matlab-for-students.blogspot.com/2020/05/matlab-variables-operators.html
Step-3:-
Here your desired file is created.
Let us try with an example:-
Our file name is MyFirstProg.m and you can follow this images.

How to Run the file that you have created??: -

Clicking the Run button on the editor window or Just typing the filename without extension in the command prompt like this:-
>> MyFirstProg
contact-form



Post a Comment

If you have any doubts regarding this topic...
feel free to ask...

Previous Post Next Post