필터 지우기
필터 지우기

Findgroups, order of unique values in an array

조회 수: 15 (최근 30일)
ardeshir moinian
ardeshir moinian 2021년 2월 3일
댓글: Stephen23 2021년 2월 4일
Hi,
I am trying to use "findgroups" in order to later split my data into different groups. But the order at which the groups are seperated is important for me. Using "findgroups" the order of groups is not "stable". How can I change that?
I did this:
[G ID]=findgroups(labels_all);
But
ID
doesn't come in that same order as
labels_all
I know that in unique, stable can fix this
q=unique((labels_all),'stable')
here q will be in order that unique values occur in labels_all.
Thank you!

채택된 답변

Stephen23
Stephen23 2021년 2월 3일
[ID,~,G] = unique(labels_all,'stable')
  댓글 수: 2
ardeshir moinian
ardeshir moinian 2021년 2월 4일
Hi Stephen,
Thank you for your answer, and do you know if I use these unique groups in
mean_data=splitapply(@mean,data,G);
would the mean_data stay in the same order as the groups that I found using unique(...,'stable') or not?
Thank you!
Stephen23
Stephen23 2021년 2월 4일
Lets try it:
G = [2,3,1,2,1,3];
D = [4,5,0,0,2,1];
splitapply(@mean,D,G)
ans = 1×3
1 2 3
Yes, splitapply returns its outputs in the order given by the values of G.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by