フィルターのクリア

How to group a matrix based on one column?

18 ビュー (過去 30 日間)
Sevgi
Sevgi 2023 年 5 月 9 日
コメント済み: Peter Perkins 2023 年 6 月 5 日
Hi,
I have a 64600x59 matrix data. I need unique values and also non-unique values grouped. Usually i use unique() function and then check if my rows matches with unique value rows, then i group by this using for loop. But this time my data is very big and it takes too much time.
I am curious about if there is any shortcut way or a function in matlab for me to group every same value in a different cell or table. This way i will be seeing non-unique values as grouped.
Do you have any ideas or suggestions?
Thank you
  3 件のコメント
Sevgi
Sevgi 2023 年 5 月 9 日
編集済み: Sevgi 2023 年 5 月 9 日
Thank you for this suggestion. I study on it and the code work for now.
T=readtable("a.xslx");
[percombine, combinenames]= findgroups(T.Combine);
meanfirstaxle= splitapply(@mean,T.("1. Axle"),percombine);
I can take mean of each groups too. But I still can't see what are group members. Is there a way for it?
Peter Perkins
Peter Perkins 2023 年 6 月 5 日
There are any number of ways to do grouped calculations, includng groupsummary/transform/filter/counts, varfun/rowfun, and (as Stephen123 says) findgroups/splitapply.
But first you need to show exactly what you have and exactly what you want.

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

回答 (1 件)

Matt J
Matt J 2023 年 5 月 9 日
編集済み: Matt J 2023 年 5 月 9 日
Usually i use unique() function and then check if my rows matches with unique value rows, then i group by this using for loop.
If using unique(), the 3rd output argument gives the group label. There is no need for a for-loop.
[values, ~, groupLabel]=unique(data);

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by