Adding rows label to the table

40 views (last 30 days)
Rajeev Kumar
Rajeev Kumar on 3 Jul 2019
Commented: Adam Danz on 3 Jul 2019
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 Comments
Guillaume
Guillaume on 3 Jul 2019
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 on 3 Jul 2019
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])

Sign in to comment.

Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!