Adding rows label to the table
21 次查看(过去 30 天)
显示 更早的评论
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!