Table - Variable names

4 views (last 30 days)
Philippa Demonte
Philippa Demonte on 27 Aug 2019
Commented: Guillaume on 17 Oct 2019
Hi!
Using the Matlab Editor** I am creating several tables from my collected experimental data relating to audio engineering, which I would like to add 'VariableNames' to such as 'SMN_-24dBSNR', 'SSN_+03dBSNR', etc as the column headers.
However, from Matlab's 'help isvarname' documentation it would seem that only letters, digits, and underscores are valid.
Is there any chance that Matlab could add the '+' and '-' sign as acceptable characters for variable names?
Is there otherwise anyway around this problem in the meantime?
For me the '+' and '-' signs are pretty important in this context. Thanks.
** Currently using Matlab R2018b; about to update to Matlab R2019b next month (September 2019) when my university's license renews.
Here is an example:
T1 = array2table(zeros(3,4),...
'VariableNames',{'SMN_-24dBSNR','SMN_-21dbSNR','SSN_00dBSNR','SSN_+03dBSNR'},...
'RowNames',{'PID01','PID02','PID03'});

Answers (2)

Guillaume
Guillaume on 27 Aug 2019
Currently using Matlab R2018b; about to update to Matlab R2019b next month (September 2019) when my university's license renews
We're not allowed to discuss pre-release versions, but I suggest you check out 2019b pre-release (or wait until 2019b comes out) for a satisfying answer to your question.
  3 Comments
KAE
KAE on 17 Oct 2019
Can you update now with R2019b details?
Guillaume
Guillaume on 17 Oct 2019
Sure,
In R2019b, there is no longer any restriction on the variable names of a table. You can have any character you want. If a table variable is not a valid variable name, you have to use the .('varname') notation, e.g.:
mytable.('SMN_-24dBSNR') %access table variable SMN_-24dBSNR
To tell readtable to preserve the original variable names,
readtable(yourfile, 'PreserveVariableNames', true)

Sign in to comment.


Matt J
Matt J on 27 Aug 2019
Is there any chance that Matlab could add the '+' and '-' sign as acceptable characters for variable names?
I don't think there is any chance. If they were to do so, the table2struct command would become invalid because structure field names containing those characters are illegal. I suppose you could argue that field names could also be made more flexible, but I'm guessing that would open a whole can of worms with the Matlab's syntax parser.
  3 Comments
Matt J
Matt J on 27 Aug 2019
No, structures have not been removed in R2019.
Guillaume
Guillaume on 27 Aug 2019
structures are certainly not going away (well, I assume, that would be a major change otherwise) and tables and structures play different roles although they do overlap.
I suspect it would be very difficult for mathworks to add support for non-valid characters in field names as this would require changes to the core of matlab.
Tables on the other hand, being plain classes, can be adapted via subsref and subsasgn overload to be more flexible.

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!