필터 지우기
필터 지우기

please help me in sort row

조회 수: 1 (최근 30일)
Triveni
Triveni 2016년 8월 8일
댓글: Triveni 2016년 8월 8일
I have a row,
x = [0 0 0 0 0 40 40 -40 -40 -40 -40 -40 -40 80 80 80 80 80 80]; x1=x;
[xi, u_x] = hist(x1, unique(x1));
output,
u_x =
-40 0 40 80
xi
xi =
6 5 2 6
but i want to sort this according to given x,
[0 40 -40 80]
and
[5 2 6 6]
should be output of both x_u and x_i respectively. please help me.

채택된 답변

Stephen23
Stephen23 2016년 8월 8일
편집: Stephen23 2016년 8월 8일
x = [0,0,0,0,0,40,40,-40,-40,-40,-40,-40,-40,80,80,80,80,80,80];
[uni,idu] = unique(x);
[cnt,idx] = hist(x,uni);
[~,ids] = sort(idu);
cnt = cnt(ids)
idx = idx(ids)
and the outputs:
cnt =
5 2 6 6
idx =
0 40 -40 80

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by