Today, I am writing this tutorial for creating and saving M-file in MATLAB. While learning MATLAB, you should know “How to create MAT file in MATLAB?”.
Why do you need a MAT-file?
If you are writing the program for solving technical computing or running Simulink model, you need to save the program as M-file in MATLAB.
What is an extension of MATLAB file?
In MATLAB, the new M-file will be saved with an extension of “m”. And MATLAB Simulink model will be saved with an extension of “mdl” or “slx”
Note: M-file is a short abbreviation of MATLAB-file. It is also called as MAT-file. Sometimes, M-file is called as the “Script file”.
How to Create MAT file in MATLAB?
Here are the following steps, you should follow for creating a new file.
- Firstly, open the MATLAB software. And click on the New Script topmost option from the Home of the MATLAB window. This new script is used for creating a new File in MATLAB. [as shown in below image]
- After selecting the new script, you will see the Editor option. You will see the Untitled new M-File for writing the new MATLAB program.
- Before writing any program or any technical computing in Command Window, you should Save the file in your desired folder.
Note: Extension of the new MATLAB file should be “mat” or ” m “ file.
MAT File Example:
For Example, Here I am saving the M-File with the naming DipsLab.m.
Sample MAT File Program (Example)
Write a MATLAB program to solve the mathematical calculation, for example, the addition of two numbers (calculate the value of ‘a’).
>> x=2; y=4; >> a=x+y a = 6
I am clicking on the Save Workspace option in the MATLAB window. And saving this file with the name of the “Addition.mat” in the new folder.
You can write more MATLAB programs using Mathematical functions.
Check following new tutorials for MATLAB learning.
- How to Start and Run MATLAB Simulink model? [With Example]
This is all about steps by step procedure- how to create MAT file in MATLAB? If you get any difficulty to execute your MATLAB file, write your query in the comment section below.
If You Appreciate What I Do Here On DipsLab, You Should Consider:
DipsLab is the fastest growing and most trusted community site for Electrical and Electronics Engineers. All the published articles are available FREELY to all.
If you like what you are reading, please consider buying me a coffee ( or 2 ) as a token of appreciation.
This will help me to continue my services and pay the bills.
I’m thankful for your never-ending support.
I have completed master in Electrical Power System. I work and write technical tutorials on the PLC, MATLAB programming, and Electrical on DipsLab.com portal.
Sharing my knowledge on this blog makes me happy. And sometimes I delve in Python programming.