Using long filenames helps greatly in managing my scripts but as we know the name length is limited by 63. There appears to be no solution at this time, or is there actually one?
-
is it the filename which is causing problem or the filename with the path ? – Hariom Singh Jun 08 '22 at 07:25
-
3Do you mean filenames or variable names? Can you give an example code to better understand your question? – Dima Chubarov Jun 08 '22 at 07:31
-
1Although the premise can be questioned, the question is technically correct. MATLAB does indeed limit the names of the script files to 63 characters. Anything long and you cannot call it in MATLAB. I believe that is what OP is referring to. You can take a look [here](https://ch.mathworks.com/help/matlab/ref/namelengthmax.html) or try it in by yourself to confirm – LNiederha Jun 08 '22 at 10:42
1 Answers
TL;DR: No, there is no way to bypass the limit
MATLAB name limits
So to clear confusion, there is no limitation on the size of file names in MATLAB. At least not imposed by MATLAB. There might be some if MATLAB calls a system command that has such limitation but that rarely happens.
There is however a limitation on MATLAB variable, names and identifiers. As this doc states, the following items are limited to 63 characters, with no way to bypass it:
- Variable names
- Structure field names
- Scripts, function and class names
- Model names
There are two main reasons for this limit:
First: It allows MATLAB to fix the size of the memory block in which the name is stored, which allows for static allocation (which is faster than dynamical).
Second: It is usually is bad practice to have long variable and function names. The idea here being that the programmer might be using a long name to store information within the name when it should actually be stored in a variable.
There is an interesting post on MATLAB answers that discusses the topic more in depth.
Discussion
You could maybe refute their second argument by saying that it is limiting for scripts and they need to have longer names but it comes to personal opinion. I would suggest short names and put additional information in the doc part of the script.
Personally, I don't think you need over 63 characters to manage your scripts properly. A correct folder architecture and use of function will help you to make things more clear than complex names ever could.
I have been coding in MATLAB for over 7 years now, built some fairly complex application, and this is the very first time I realize there is a size limit.
And finally it is really tenuous to read long script and variable names and I'm not sure it actually helps the reader.
For these reasons maybe it would be interesting to you to consider different naming conventions.

- 911
- 4
- 18
-
1*"I have been coding in MATLAB for over 7 years now, built some fairly complex application, and this is the very first time I realize there is a size limit."* Same, but 10 years. Completely agree with the answer of "you should just not be doing this" – Ander Biguri Jun 08 '22 at 11:12
-
2Note too that [namespacing](https://stackoverflow.com/a/2748740/3978545) a folder with a `+` allows for uniquely specifying functions with similar or identical names, and makes function organisation simple with consistently short function names, which can be called from a long chain of nested folders exceeding 63 chars if needed. – Wolfie Jun 08 '22 at 16:47
-
One reason for long variable names might be interoperability. Suppose variable names are created automatically from metadata stored by a different program with longer variable names that share the same prefix. Then one would have to repack the data before processing it with MATLAB. – Dima Chubarov Jun 08 '22 at 16:59
-
Well ideally you'd take that into account as well. If you create variables in MATLAB then you have to take that into account. (And creating different variables from data is a pain, you'd probably use an array or a cell array). And if your data is stored in files, then you don't have the limitation since those are not `.m` files. You might be correct for some very specific situation but I would expect that to happen extremely rarely. – LNiederha Jun 09 '22 at 07:37
-
Appreciate your very detailed answer. I agree with you on your first point. Just fancy that with nowadays hardware, the impact brought by the variable filenames might not be all that significant? Forgive me if I'm wrong. For the second point I'm afraid the long filename does ease the file management coz it eliminates the conversion between the short names, if used, and the original long names. Does anyone concur with me? – farhill Jun 10 '22 at 03:23
-
This is a Q&A site, not a discussion forum. @farhill it doesn't really matter if people concur with you unfortunately, you've asked whether there is a workaround and the answer is ultimately contained in the first sentence of this answer, "no", you can close this question by marking the answer as accepted. Whether or not modern hardware should be able to handle long file/variable names is off topic – Wolfie Jun 10 '22 at 07:29