フィルターのクリア

How to get stats by group

3 ビュー (過去 30 日間)
Mekala balaji
Mekala balaji 2020 年 8 月 16 日
回答済み: Image Analyst 2020 年 8 月 16 日
Hi,
I have cell array as shown below:
data:
Name Age rank
A 20 12
B 20 42
A1 13 2
A2 22 3
B2 20 32
N 22 19
How to get "min, max, mean, std" by group. Now use below code:
unq_age= unique(dsts(2:end,2))
for i =1:numel(unq_age)
tmp =unq_age(i)
idx= cellfun(@(x)isequal(x,tmp),data(:,2));
tmp_data = data(idx,3)
min_x=min(str2double(tmp_data))
max_x=max(str2double(tmp_data))
mean_x=mean(str2double(tmp_data))
std_x=std(str2double(tmp_data))
but is there any function to get group stats? in one line

回答 (2 件)

Mohammad Sami
Mohammad Sami 2020 年 8 月 16 日
You can use the function group summary. See documentation for more details. https://www.mathworks.com/help/matlab/ref/double.groupsummary.html

Image Analyst
Image Analyst 2020 年 8 月 16 日
If you have the stats toolbox, try grpstats(). Otherwise try splitapply().

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by