필터 지우기
필터 지우기

Not able to excecute the code

조회 수: 8 (최근 30일)
Rajeev Kumar
Rajeev Kumar 2019년 6월 21일
댓글: Walter Roberson 2019년 7월 4일
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.

채택된 답변

Aravind Ravikumar
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
Rajeev Kumar
Rajeev Kumar 2019년 7월 4일
Thanks Walte size. Here is the result:
size(table)=0x3
h=table.Properties.VariableNames
h =
1×3 cell array
{'tab1'} {'t'ab2} {'tab3'}
Could you please comment on this?
Walter Roberson
Walter Roberson 2019년 7월 4일
With 0 rows you must have 0 row names.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Akshay Malav
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
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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by