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