- If "VariableNamingRule" is set to "preserve", variable names are not altered to conform to MATLAB identifier rules, but may still be truncated or changed if:
- The name exceeds the maximum allowed length ("namelengthmax", which is 63 characters in R2024b).
- There are duplicate variable names after truncation.
- During import options detection, all variable names are truncated to "namelengthmax" and made unique if necessary.
- When "readtable" reads the file, the set of variables selected (via "SelectedVariableNames") can affect how duplicate names are resolved after truncation. This may result in variable names in the output table not matching those in "opts.VariableNames" or "opts.SelectedVariableNames".
Why are column names truncated while using "readtable" with long variable names in MATLAB R2024b
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 16 Ott 2025 alle 0:00
Risposto: MathWorks Support Team
il 17 Ott 2025 alle 15:40
When using "readtable" with import options in MATLAB R2024b, I noticed that some column names are unexpectedly truncated or renamed, especially when the original variable names are long. This occurs even though the correct variable names are present in the import options. Why does this happen, and is there a workaround?
Risposta accettata
MathWorks Support Team
il 16 Ott 2025 alle 0:00
In MATLAB R2024b, when using the "readtable" function with an import options object (created using "detectImportOptions"), variable names from the file are processed according to the following rules:
Please refer the below link to learn more about variable naming rules:
If several variable names in the file are similar and exceed 63 characters, truncation can cause otherwise unique names to become duplicates. MATLAB then automatically appends suffixes (e.g., "_1", "_2") to ensure uniqueness. However, if only a subset of these variables is selected for import, the de-duplication process may assign different names than expected, depending on which variables are included.
To avoid this issue in R2024b, explicitly set the "ReadVariableNames" parameter to "false" when calling "readtable". This instructs MATLAB to use the variable names specified in the import options object rather than reading them from the file, which prevents unexpected truncation and renaming:
T = readtable('your_file.txt', opts, 'ReadVariableNames', false);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!