Set different row name in table with certain range of rows

12 views (last 30 days)
Hye, may i know how to set the different row names in table with certain range of rows. i also have a quite big table full with data which is in form of 361x1 table.
Example of my problems:
i want to label A from row 1 until 19, B from row 20 until 39 and it goes on and on until my table has complete row names. The range to set the label is every 19 rows and it change to another label.
Therefore, i hope that somebody can help to solve my problems. I had try to look at documentation in matlab but still confuse and cannot figure it out. I really need your help and it really will be much appreciated. Thank you.
  6 Comments
Nurul Atifah
Nurul Atifah on 4 May 2018
Ohh I see so I need to add another column for it. Ok, now I know enough that table cannot make row names to be duplicate but is it possible if I change back to cell or array and put row names in it or is it just the same as the table? The reason why I want to put the same name because the few row of data that I have is actually in the same category. And I haq quite large data. I need to sort it by rows.
Guillaume
Guillaume on 4 May 2018
if I change back to cell or array and put row names
Neither of these can have names for row duplicate or otherwise. Only tables can have row names.
If it's for categorising the rows, then simply add a new column. Rather than using char arrays or strings, I would recommend you use categorical arrays

Sign in to comment.

Answers (1)

Guillaume
Guillaume on 4 May 2018
Edited: Guillaume on 4 May 2018
As we've established you can't use the row name property for labelling your rows but you can just use a new column. To label the new columns in order in group of 19:
labelnumber = repelem((1:ceil(height(yourtable)/20))', 20);
labelnumber = labelnumber(1:height(yourtable));
yourtable.label = compose('label%d', labelnumber);
or even better use categorical arrays instead of char arrays, so replace the last line by
yourtable.label = categorical(compose('label%d', labelnumber));
You can then sortrow by the label column or use rowfun with 'GroupingVariables', 'label' to calculate stats for each group.
P.S.: I've grouped the rows in groups of 20. Your question is ambiguous on the numbers of elements in each group. row 1-19 is 19 rows, but row 20-39 is 20 rows!

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!