variable name length exceeds 63 characters

236 views (last 30 days)
Hello, I'm new here:) maybe you can help me with a problem. I need to use some variables whose names are exceeding 63 characters. Does anyone have any idea? I must fix this problem quickly:D
Thanks in advance!
  1 Comment
Nathan Greco
Nathan Greco on 25 Jul 2011
As always, examples help. What do your variable names look like?

Sign in to comment.

Accepted Answer

Jan
Jan on 25 Jul 2011
Your demand for more than 63 characters sounds, like you store important values in the name instead of the contents of a variable. A program using such long symbols is nearly unreadable and debugging will be ridiculous hard.
Beside the fact, that the limit of 63 characters is hard coded and cannot be changed in MATLAB, I assume that there is a misconcept in your program design. Please explain, why you want to stuff so much information in the names.
  10 Comments

Sign in to comment.

More Answers (7)

AL REY
AL REY on 14 Jan 2020
Hello, I might reopen this topic. But i would like to add a reason why we do have so long name. On my side i'm using '.mf4' data from CANAPE (Vector), the recorded label are often the software structure and exceed the 63 limit, it's also something that we can change unless we change the software dictionary. Some native matlab function (blockset) as mdf('name.mf4') and read can't deal with such naming.
It will be nice to have a way to avoid that limit.
  1 Comment
Walter Roberson
Walter Roberson on 15 Jan 2020
Edited: Walter Roberson on 15 Jan 2020
Make the recorded label data rather than a variable name at the MATLAB level.

Sign in to comment.


Oleg Komarov
Oleg Komarov on 25 Jul 2011
Cannot help, but why do you need such long names?
Names are meant to identify quickly a variable, if you're trying to include meta data in the name I would rather suggest to create a structure with meta fields and data field.
s.description = 'longdescription'
s.place = 'myPlace'
s.data = 10;
EDIT
To search for files keep a cell array with short names (the ones you actually save the file as) and the long ones:
names = {'ak47_19992102', 'long description'
'ak47_19992102', 'another long description'};
search on the second column and match with teh real names.
Or using the struct array you can search through all the s.description
Also, are you using/planning to use eval?

Diana Acreala
Diana Acreala on 25 Jul 2011
Variable name must be explicit, among others should include the name of a graph axis and exceeds 63 characters (to do a search when needed).. it's a must to do this and I can't find any solution..
Thanks for you answer :)

Walter Roberson
Walter Roberson on 25 Jul 2011
This is not possible in MATLAB.
Perhaps it would make more sense to break your variable up in to a structure. For example, instead of
one_two_three_four_five
you could use
one.two.three.four.five
which would be a structure array.

Walter Roberson
Walter Roberson on 25 Jul 2011
Possibly the Map Container would be suitable for your work, allowing you to index variables according to arbitrary strings. See here

Diana Acreala
Diana Acreala on 26 Jul 2011
OK! Thank you all for your answers!
I will change my idea of solving the problem, I decided to reorganize the GUI and it is not necessary to create a structure. However, is a good idea for the future. Now I have many variables and the client does not know yet how he wants the variables to be organized.
Now I'm stuck on something else, but I will write a message with a new topic:D
Success!!
  4 Comments
Walter Roberson
Walter Roberson on 17 Jul 2017
... and posting as a new Question would be a good idea.

Sign in to comment.


Stéphane
Stéphane on 2 Sep 2022 at 16:18
Hello,
I reopen the topic: on my side also I need variable names longer than 63 characters.
Yes these long names are providing a lot of information describing the variable and are especially useful to name the variables in the interface of a generated code (from a model for example). Of course this information could also be stored in a metadata structure, but If the code is then used by a caller not able to handle this metadata, this information will be lost (or at least not visible at the caller's level). The most secure and portable way to link a metadata to it's variable is to put this data in the name of the variable.
I'm nevertheless not that much intererested in debating if it is a good practice or not to use long variable names. One can have this need and it's really unfortunate that Matlab limits the variable names to such a low value. Is there a real technical reason behind ? I hope that a way could be found in the future to get rid of this limitation.
  2 Comments
Walter Roberson
Walter Roberson on 2 Sep 2022 at 18:42
Your argument for the reason to support long variables does not have any natural limit on variable name lengths. You find 63 to be too small, but since you are using generated code that might have a number of different semantic layers to each variable, clearly 255 might be too small for your purposes as well. How about 65535? You could be doing generated code operating on generated code, so better not limit it to 65535 either.
It follows that your only hard limit should be the maximum array size supported on the hardware MATLAB runs on, same as the maximum array size supported by MATLAB, 2^48-1 bytes. The Intel x64 hardware in theory has 64 bit address paths, but in practice the chips for all publicly known versions are only designed with 48 address lines.
So, you have your 7 terrabyte variable name in one function, and by your arguments about callers, you expect other functions to be accessing the same variable name (you do not expect the names to be local to a single function.) It would obviously be inefficient to store the name twice in MATLAB. This suggests that instead of storing variable names in fixed-length structures, that MATLAB should instead be allocating character vectors for each of them and the symbol tables should point to the character vector -- and that this all should be a global table with reference counters, and some way (hash tables?) to quickly locate individual variables.
Since this is all for the convenience of generated code, it follows that at the same time, MATLAB should remove or alleviate the restriction on which characters are permitted in variable names, permitting at the very least the "alphabetic" letters in multiple languages, and permitting diacretic marks.
Should all be easy, right? No "real" technical reason against doing it, right?
Based on MISRA C 2004:
Rule 5.1 (required): Identifiers (internal and external) shall not rely on the
significance of more than 31 characters. [Undefined 7; Implementation 5, 6] The
ISO standard requires internal identifiers to be distinct in the first 31 characters
to guarantee code portability. This limitation shall not be exceeded, even if the
compiler supports it. This rule shall apply across all name spaces. Macro names
are also included and the 31 character limit applies before and after substitution.
The ISO standard requires external identifiers to be distinct in the first 6
characters, regardless of case, to guarantee optimal portability. However this
limitation is particularly severe and is considered unnecessary. The intent of this
rule is to sanction a relaxation of the ISO requirement to a degree commensurate with
modern environments and it shall be confirmed that 31 character/ case significance
is supported by the implementation. Note that there is a related issue with using
identifier names that differ by only one or a few characters, especially if the
identifier names are long. The problem is heightened if the differences are in
easily mis-read characters like 1 (one) and l (lower case L), 0 and O, 2 and Z,
5 and S, or n and h. It is recommended to ensure that identifier names are always
easily visually distinguishable. Specific guidelines on this issue could be placed
in the style guidelines (see section 4.2.2).

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!