MATLAB Answers

1

variable name length exceeds 63 characters

Asked by Diana Acreala on 25 Jul 2011
Latest activity Commented on by Walter Roberson
on 9 Jul 2019
Accepted Answer by Jan
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

As always, examples help. What do your variable names look like?

Sign in to comment.

6 Answers

Answer by Jan
on 25 Jul 2011
 Accepted Answer

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.

  7 Comments

No Jan, that's another variable, my comment was for any time someone read the comment not just that day :) btw keep up the good work.
Hi Jan,
"Beside the fact, that the limit of 63 characters is hard coded and cannot be changed in MATLAB"... Sounds to me like perhaps there is a misconception in MathWorks program design.
Anyway, I agree that programmers should generally avoid using long variable names when unnecessary, but why limit users in such a way? For example, scientists working with CF Standard Names (http://cfconventions.org) have to come up with workarounds for this kind of stuff.
It would be great if users could configure the char limit.
Misconception?? I would not say so. Real programming involves a lot of tradeoffs.
The matlab internal symbol table for functions involves several pools, each holding different scopes of variables. Each of the pools involves fixed length entries, including the literal symbol, probably in uncounted null padded form. Each pool consists several blocks allocated from a fixed size block memory allocator. Adding a new variable involves finding an unused slot and writing a fixed length entry into it. It would not surprise me if the flag indicating whether the slot is used, is whether the first byte of the name field is null.
Returning from the function involves walking pools, checking if the slot is used, and passing the mxarray pointer to the routine that decrements the reference count and returns the memory for the mxarray upon reaching 0, potentially triggering destructors along the way. Once the pool is walked the fixed length blocks are returned to the small block pool that matlab keeps. MATLAB never fragments those blocks, only hands out full blocks, so allocation routines can be efficient. Because the symbol names are part of the fixed length entries (that is, a strut array), there is no need to do memory management on the symbol names, as would be required if the symbol names were a pointer to a C++ string object.
In this scheme, the only memory allocation in the symbol table is the case where the existing fixed length blocks are full and it is time to allocate a new one out of the fixed length blocks pool.
If the user were permitted to control the maximum variable name length then a significant amount of memory management would be required just for handling the symbol names, and comparing names would require a string comparison function call instead of just comparing a fixed memory block (64 bytes)

Sign in to comment.


Answer by 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?

  0 Comments

Sign in to comment.


Answer by 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 :)

  1 Comment

Se the edit in my answer.

Sign in to comment.


Answer by 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.

  0 Comments

Sign in to comment.


Answer by 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

  0 Comments

Sign in to comment.


Answer by 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

Show 1 older comment
You're using GetEchoString and attempting to use the output to create a variable by that name using eval? Dynamically creating variable names is somewhat discouraged around here and IMO for good reason. Tell us a little more about what you're trying to do with the output from GetEchoString and we may be able to suggest alternatives.
Jan
on 17 Jul 2017
@Clarisse: Please post the relevant part of your code, such that we can reconsider, what you are trying to do.
... and posting as a new Question would be a good idea.

Sign in to comment.