How to organize a table?
Show older comments
I have a table around 700 rows and 7 columns. The second column is time. I have 5 different times. The last column is "cell type" which is an integer from 0 to 4. I need to know that at time=0 how many "cell type=3" exists? how many "cell type=4" exists? and do this for all times.
Is varfun appicable in this case?
Thanks 

3 Comments
madhan ravi
on 16 Aug 2019
Edited: madhan ravi
on 16 Aug 2019
Do not let the readers guess, so that they don't spend more time in guessing how the actual data looks like! Always post a sample data of what you're working with. You have always ignored the comments asking for the sample data until now! Posting pictures of data is completely pointless and useless. Attaching a file as .mat would be better to work with.
Zeynab Mousavikhamene
on 16 Aug 2019
Edited: Zeynab Mousavikhamene
on 16 Aug 2019
Andrei Bobrov
on 16 Aug 2019
Please read about varfun.
Accepted Answer
More Answers (2)
Zeynab Mousavikhamene
on 16 Aug 2019
0 votes
Andrei Bobrov
on 16 Aug 2019
Edited: Andrei Bobrov
on 16 Aug 2019
T = readtable('img1.txt');
out = varfun(@sum,T,'GroupingVariables',...
{'time','cell_type'},'InputVariables','cell_type');
out = out(:,1:end-1);
or
[A,out] = findgroups(T(:,{'time','cell_type'}));
out.counts = accumarray(A,1);
Categories
Find more on Matrices and Arrays 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!