Home > Blockchain >  Is there a workaround to get Matlab to support long filenames?
Is there a workaround to get Matlab to support long filenames?

Time:06-11

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?

CodePudding user response:

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.

  • Related