How to Create MAT file in MATLAB? [Save and Run]

MATLAB Programming Feature image

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’).

Solution:

Let consider,

>> x=2; y=4;

>>  a=x+y

a     =

          6

Here,

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.

What’s Next?

Check following new tutorials for MATLAB learning.

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.

coffee

I’m thankful for your never-ending support.

6 thoughts on “How to Create MAT file in MATLAB? [Save and Run]”

  1. Seriously I appreciate this from you, I was almost crying because I needed this MATLAB to run my model for my project but my commands are not in my m file, thank you for this help, God bless you.

    Reply

Leave a Comment