# Clarification about using only the first 'namelengthmax' characters of the name

6 visualizaciones (últimos 30 días)
Bandar el 30 de Dic. de 2019
In Matlab documentation, it states the following
Although variable names can be of any length, MATLAB uses only the first N characters of the name, (where N is the number returned by the function namelengthmax), and ignores the rest. Hence, it is important to make each variable name unique in the first N characters to enable MATLAB to distinguish variables.
In my machine, N = 63. But if I attempt to use the following code:
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=5
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab=6
Matlab did indeed create two variables which contradicts what mentioned in the documentation. Any clarifications!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Image Analyst el 30 de Dic. de 2019
How did you figure out N? Anyway, your variable length is 61, which is not more than 63 so you'll be okay.
alen = length('Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
blen = length('Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab')
alen =
61
blen =
61
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Adam Danz el 30 de Dic. de 2019
l = namelengthmax provides the maximum variable name length.
If the first l characters of two variable names are the same, the second one will overwrite the first.
Here are two variable names that are 64 characters long and only differ by the 64th character
clear
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1;
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab = 0;
The result is a warning. Both variable names are truncated to 63 characters and the 2nd one overwrites the first.
Warning: 'Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' exceeds the MATLAB maximum name length of 63
characters and will be truncated to 'Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
Warning: 'Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab' exceeds the MATLAB maximum name length of 63
characters and will be truncated to 'Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.
List all variables in workspace
who()
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Iniciar sesión para comentar.

### Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by