Table - Variable names
4 ビュー (過去 30 日間)
古いコメントを表示
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'});
0 件のコメント
回答 (2 件)
Guillaume
2019 年 8 月 27 日
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 件のコメント
Guillaume
2019 年 10 月 17 日
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)
Matt J
2019 年 8 月 27 日
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 件のコメント
Guillaume
2019 年 8 月 27 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!