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
  1 件のコメント
Triveni
Triveni 2016 年 8 月 8 日
Thank you :D

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by