Filter löschen
Filter löschen

please help me in sort row

1 Ansicht (letzte 30 Tage)
Triveni
Triveni am 8 Aug. 2016
Kommentiert: Triveni am 8 Aug. 2016
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.

Akzeptierte Antwort

Stephen23
Stephen23 am 8 Aug. 2016
Bearbeitet: Stephen23 am 8 Aug. 2016
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

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by