tabulate cell2table

8 views (last 30 days)
NA
NA on 25 Oct 2020
Commented: NA on 26 Oct 2020
I have a ‘group_belong’ like this:
The group_belong{2} is:
The group_belong{4} is:
I use the below code to remove empty cell and put the remain one vertically.
group_belong = group_belong(~cellfun('isempty',group_belong));
group_belong = vertcat(group_belong{:});
Then, I convert this cell array to table and put the variable name.
T = cell2table(group_belong,'VariableNames',{'A' 'B' 'C' 'D' 'E' 'I' 'R' 'T'});
But I got this result:
I do not know how to fix column 3 to this:

Accepted Answer

Walter Roberson
Walter Roberson on 25 Oct 2020
Your C variable in your table is probably already stored the way you want. It is the variable browser that is displaying separate columns, but T.C would be a 3 x 3 array [1 2 5;2 4 5; 2 4 5]
It is possible to get the kind of display you ask for out of the variable browser: it would show up like that if each row of T.C were a cell array. cell2table() does not create those kinds of entries automatically if all of the rows are the same size (like your column 3) but does if the rows are not all the same size (like your column 8).
I could suggest various ways to deliberately cause cells the same size to be stored as cells, but it strikes me that the easiest way might be to add an empty cell row onto the bottom of the input data, create the table, and then remove the last row.
  3 Comments
Walter Roberson
Walter Roberson on 26 Oct 2020
If you know ahead of time which variables you want to become cells then when you do
group_belong(end,:) = {[]};
instead do
group_belong(end,[those column numbers]) = {[]};
NA
NA on 26 Oct 2020
Thank you.

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!