Adding rows label to the table

조회 수: 16 (최근 30일)
Rajeev Kumar
Rajeev Kumar 2019년 7월 3일
댓글: Adam Danz 2019년 7월 3일
I am stuck in one implementation where I want to create a table with just column and row name. I am trying in the following way
Step1 : tab1 = cell2table(...) ; tab2=cell2table(...) ;tab3=cell2table(...)
Step2 : table = [tab1 tab2 tab3]
step3 : table..Properties.RowNames = x_name ; x_name is a cell array of specied element (say it is of size 1x20)
This is throwing the following error : The RowNames property must contain one name for each row in the table. Can I create a table with only rows and column name
  댓글 수: 2
Guillaume
Guillaume 2019년 7월 3일
I don't know what you mean by only rows and columns name.
In theory your code would work, as long as the table you created has indeed 20 rows. If not, as the error message says the number of elements of x_name must match the number of rows. You can't have unnamed rows.
So, most likely the problem is with the code you don't show.
Note that you should only call cell2table once. You can concatenate the cell arrays beforehand. That would be more efficicent than concatenating tables.
Adam Danz
Adam Danz 2019년 7월 3일
Just as the error indicates, the number of row names needs to equal the number of rows os your table. numel(rownames) == size(table,1).
Also, assuming your cell arrays all have the same number of rows, you could probably build your table more easily like this
table = cell2table([c1, c2, c3])

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by