Set different row name in table with certain range of rows
12 views (last 30 days)
Show older comments
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
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
Answers (1)
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!
0 Comments
See Also
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!