In an earlier post, I have shared steps by steps procedure for saving and running your first MAT file program in MATLAB.
There are some strict rules you should follow for choosing MATLAB script or MAT-file name.
Rules for Writing MATLAB Script / M-File Name
While saving MAT-file, if you don’t choose MATLAB file name as per their standard naming convention, you will see the following error message.
MATLAB will not be able to run the file <matlab_filename> unless you change its name.
To avoid error, follow the rules specified below.
1. Never use the M-file name in the MATLAB function or command and vice-versa.
In the MATLAB, Don’t use the same name in Command Window or M-file’ s name. So, you should check the files name before naming the M-file.
If you want to check the file name you can use the ‘help’ instruction.
>> help <filename_to_check>
For Example,
Suppose, we want to save M-file name as DipsLab. As of now, we don’t know if this filename is used or written in the in MATLAB command earlier.
So, we want to check the M-file name i.e. “DipsLab” by using the help Instruction.
>> help DipsLab
In the Command Window, if this file name is not used, you will see the message as
DipsLab not found.
Thus, you can use this file “DipsLab” name.
2. Never use the number before the file name.
At the beginning of the MAT-file, don’t use the digit or symbol. Otherwise, the files will not be saved.
For example,
1stock.m (It is the wrong format) stock1.m (It is the correct format)
3. Never use blank space in the file name.
Don’t use the space in the file name. But, you can use the underscore ‘_’ between two sentences or file name.
For example,
Electrical Stuff. m (It is the wrong format) Electrical_stuff.m or ElectricalStuff. m (It is the correct format)
These are the 3 most important precautions and rules for writing a MATLAB script.
What’s Next?
I have shared the tutorials base on creating a new model and save the model file in MATLAB Simulink. This link as ‘How to Start and Run MATLAB Simulink model? [with Example]’.
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.
I read your new stuff regularly. Your story-telling style is awesome. keep up the good work!
Thanks, Sandy Rubin for reading the tutorials.
Also, I started the weekly Newsletter, where I share the electrical tutorials, information and useful electrical related posts and kinds of stuff through the mail.
You can subscribe to my Newsletter to get all updates in your email inbox.
Your website is also very good. And really, I appreciate your work.
Thanks, Aniket 🙂
It’s really a cool and useful piece of information. I am satisfied that you shared this useful information with us. Thanks for sharing.
Thanks, Comaco Pitber for reaching to my blog.
I constantly spent my half an hour to read this web site’s articles or reviews daily along with a mug of coffee.
Thanks, John for reaching out to my portal.
Thanks very nice blog!
Very good article.
Thanks, Kapil:)
Very good post. I absolutely appreciate this website and continue the good work!
Thanks, Rizwan for sharing kind words for DipsLab.
Good explanation!
Thanks, Ram:)
This is a great blog.
Thanks, Mortin:)
This article is really a nice one it helps to easily learn.
Thanks 🙂