why matlab won't support file name length more than 63 char?
Show older comments
Is there any limitations with respect to operating system, controllers or anything?
Please can someone explain me clearly what could be the possible reason?
1 Comment
Henric Rydén
on 22 Jun 2015
I have never heard of this issue. I tried creating a folder with 115 characters in it and it worked.
Accepted Answer
More Answers (1)
Steven Lord
on 22 Jun 2015
2 votes
If you want to create a MAT-file with an extremely long name you can do that, as MAT-file names is not one of the categories listed in that documentation. If you want to create a variable or a script file with an extremely long name, you will receive a warning and the name will be truncated.
I agree with Jan's assessment -- if you are trying to create a variable with a 70, 80 character name you're probably trying to encode some information in it that is more appropriate to store as data rather than as part of the name. For that I'd consider a separate variable or storing the two pieces of data in a struct array.
8 Comments
M R
on 6 Dec 2017
One problem with this is that the 63 chrachter limit, as of r2016a, appears to apply to scripts as well.
Best practices for record keeping in digital lab notebooks suggests maintaining dates and identifying information in the filename, in order to clearly organize records of past work in a way that can be searched via the filesystem.
By forbidding scripts from having long names, Mathworks is limiting the usability of Matlab for exploratory data analysis, as it impedes detailed record keeping of past commands in script files.
Mind you, my use case doesn't require absurdly long file names, just on the order of 100 characters or so. Truncating the name will cause incompatibility with records elsewhere in the data processing pipeline, and is simply not an option.
Steven Lord
on 6 Dec 2017
Yes, this limit applies to script file names, function file names, class names, method names, variable names, struct array field names, etc. As far as I'm aware it has for at least the past 16 years, though the limit on the identifier length has increased once during my tenure at MathWorks.
I did a quick Google search for best practices for lab notebooks and none of the half dozen or so hits I found recommended storing metadata in the file name. Could you post a link to a best practices document in which that recommendation appears?
You mention "Truncating the name will cause incompatibility with records elsewhere in the data processing pipeline" -- can you say a bit more about your data processing pipeline? Are you using some other software package that recommends or requires files to be named in a particular format?
KAE
on 1 Aug 2018
Here is an example of hitting the mfile name length limit, intended to show that it can legitimately be a hindrance. I got this error on R2018a in Windows 10 when I was trying to run a mfile with a long name, and the name was truncated. The long name was convenient because I had many different versions of a similar mfile in the same folder, each intended for a different treatment of some data. I kept finding something different that the program had to do with the data, and the mfile name was a convenient way to indicate what aspect of the data I was looking at.
Steven Lord
on 1 Aug 2018
The long name was convenient because I had many different versions of a similar mfile in the same folder, each intended for a different treatment of some data.
Can you give an example of this? Are your files named something like "processDataSetForPatients_operateOnName", "processDataSetForPatients_operateOnWeight", "processDataSetForPatients_operateOnHeight", etc.?
How similar are those "similar mfile" scripts, functions, or classes? If they're the same except for say the name of a field in your data on which they operate, I recommend unifying them into one function that accepts the name of the field on which to operate as data instead of including that information as metadata stored in the name of the program.
I kept finding something different that the program had to do with the data, and the mfile name was a convenient way to indicate what aspect of the data I was looking at.
I still suspect there is a different way of organizing your scripts / functions / classes that avoids needing to use a file name longer than 63 characters.
One such option is packages; the fully qualified name of a package function can be longer than 63 characters so long as neither the package name nor the name of the function inside the package exceeds 63 characters. I just made a package function whose fully qualified name is 83 characters long and I was able to call it. [It adds its inputs together.]
>> length('abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.sampleAlphabetPackageFunction')
ans =
83
>> z = abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz.sampleAlphabetPackageFunction(1, 2)
z =
3
How similar are those "similar mfile" scripts, functions, or classes?
80% of the code lines might be the same. In each, I am changing algorithms and aspects of the data that I use. It is ugly trial and error code not meant to share with anyone else; once I figure out what works, it might make sense to clean it up. I need to retain the 'error' code because I need to keep track of what didn't work, so I don't try it again later.
One such option is packages
Can you give an example of this?
I'll make some filenames up to show the trial and error process,
engine_temperature_model_left_sensor_measurement_no_lowpass.m engine_temperature_model_right_sensor_measurement_10min_lowpass.m engine_temperature_model_include_humidity_terms.m engine_temperature_model_internal_and_ambient_sensors.m
And regrettably they may be in a directory with a long title since that is how I keep track of different data collection projects, .../Projects/EngineTemperature/Measurements/Interior Track/
Walter Roberson
on 6 Aug 2018
Subdirectories.
Adam
on 7 Aug 2018
I can't actually find the section on packages in the Matlab help apart from this one which focuses on classes, but it is even simpler for functions.
Simply create a folder with a '+' at the front of its name and that becomes a package e.g.
+engine_temperature_model
Then inside that folder you create files called:
left_sensor_measurement_no_lowpass.m
right_sensor_measurement_10min_lowpass.m
etc
And when you refer to them in code or call them on the command line you refer to them as e.g.
engine_temperature_model.left_sensor_measurement_no_lowpass.m
i.e. the package name followed by '.' followed by the name, so the final thing is very similar to your long name, but you syphon off that common prefix into a package name.
I ebb and flow on whether or not I like packages. Since I write mostly classes I recently ended up using packages for inheritance which leads to the bizarre situation of me having loads of files with exactly the same name because the descriptive part that differs (the specialisation) is in the package name now rather than the filename, so when I open them in the editor they just all show up with the same name! They can still be useful for collecting together code though, and if you have a long scope where you refer to many functions from the same package you can just put e.g.
import engine_temperature_model
at the top and then you can just refer to each by its filename without needing to constantly prefix the package name.
KAE
on 13 Aug 2018
This is good to know about, thanks!
Categories
Find more on Naming Conventions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!