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.
Table of Contents
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>
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.
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.
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.
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.