Not able to excecute the code
8 ビュー (過去 30 日間)
古いコメントを表示
I am trying to execute following codes :
rows={'A','B'};
data = cell(0,5);
T = cell2table(data);
T.Properties.RowNames = rows;
Matlab is throwing an error :The RowNames property must contain one name for each row in the table.
Can anybody comment if I am missing anything? I will appreciate any help.
0 件のコメント
採用された回答
Aravind Ravikumar
2019 年 6 月 21 日
Hey, cell(0,5) returns a 0x5 empty cell array. That is why row number isn't matching with rows variable. You should use You can simply create a cell array using the command,
data = {0,5}
Also, in this example data is a 1x2 cell array. Hence it has only one row. To change that row name, you could do something like,
rows={'A'};
data = {0,5};
T = cell2table(data);
T.Properties.RowNames = rows;
For creating a 2x1 cell array, you'll have to use
rows={'A','B'};
data = {0;5};
T = cell2table(data);
T.Properties.RowNames = rows;
5 件のコメント
その他の回答 (1 件)
Akshay Malav
2019 年 6 月 21 日
編集済み: Akshay Malav
2019 年 6 月 21 日
First change the number of rows from 0 to 1 and correspondingly the rows array should contain only 1 element either 'A' or 'B'. Run it , it will work fine
Here is the code
rows={'A'};
data = cell(1,5);
T = cell2table(data);
T.Properties.RowNames = rows;
1 件のコメント
Walter Roberson
2019 年 6 月 21 日
Right. You can only have a row name for a row that exists. You cannot put in placeholder row names for rows to be added later.
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!