フィルターのクリア

How to organize a table?

3 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 16 日
編集済み: Andrei Bobrov 2019 年 8 月 16 日
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 Capture.JPG
  3 件のコメント
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 16 日
編集済み: Zeynab Mousavikhamene 2019 年 8 月 16 日
@madhan ravi: I added a photo. If you track my question, I have added data to some of my questions.
Andrei Bobrov
Andrei Bobrov 2019 年 8 月 16 日
Please read about varfun.

サインインしてコメントする。

採用された回答

Jon
Jon 2019 年 8 月 16 日
編集済み: Jon 2019 年 8 月 16 日
You could do this with a simple loop I'll assume your table is called mytable
% find maximum possible value for cell type
cellTypeMax = max(mytable.cell_type)
% find the row numbers of all the rows with time = 0
irow = mytable.time == 0
% loop through the rows at time zero counting number of each occurence
count = zeros(cellTypeMax,1); % preallocate
for k = 1:cellTypeMax
count(k) = sum(mytable.cell_type(irow)==k)
end
You could also get fancier and eliminate the loop using histcounts (or histc in earlier versions)
% find maximum possible value for cell type
cellTypeMax = max(mytable.cell_type)
% find the row numbers of all the rows with time = 0
irow = mytable.time == 0
% define bin edges assume that cell types start at 1
edges = [0.5:1:cellTypeMax+1];
% count occurences within rows that are at time zero
count = histcounts(mytable.cell_type(irow),edges)

その他の回答 (2 件)

Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 16 日
I used celltracker_group = varfun(@mean,celltracker,'GroupingVariables',{'time','cell_type'});
and it worked perfectly. It produces GroupCount which is exactly what I want.

Andrei Bobrov
Andrei Bobrov 2019 年 8 月 16 日
編集済み: Andrei Bobrov 2019 年 8 月 16 日
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);

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by