Matlab's 'VariableNames' not accepting mix of numerical & non-numerical entries

1 回表示 (過去 30 日間)
John
John 2017 年 1 月 23 日
コメント済み: John 2017 年 1 月 24 日
Suppose we have a 1x3 table:
A=table(1,2,3);
whose header names should contain a mix of numericals and non-numericals:
A.Properties.VariableNames={'from 1st-5th' 'from 6th-10th' ...
'from 11th-15th'};
This generates the following error:
'from 1st-5th' is not a valid variable name.
What I read through (and tried) already: sprintf function, whereas the formatSpec part was rather confusing. Furthermore I read about eval and would like to know whether this is helpful in my context.
  1 件のコメント
Stephen23
Stephen23 2017 年 1 月 24 日
"I read about eval and would like to know whether this is helpful in my context"
eval is almost never helpful in any context:

サインインしてコメントする。

採用された回答

Jorge Mario Guerra González
Jorge Mario Guerra González 2017 年 1 月 23 日
編集済み: Jorge Mario Guerra González 2017 年 1 月 23 日
It does not accept it because it has spaces and not because it has alphanumeric characters.
It will allow this, for example:
A.Properties.VariableNames={'from_1st_5th' 'from_6th_10th' 'from_11th_15th'}
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 1 月 24 日
"The variable names that you assign must be valid MATLAB® variable names"
John
John 2017 年 1 月 24 日
thanks a lot, this work-around solution does its job for now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by