please help me in sort row

1 vue (au cours des 30 derniers jours)
Triveni
Triveni le 8 Août 2016
Commenté : Triveni le 8 Août 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.

Réponse acceptée

Stephen23
Stephen23 le 8 Août 2016
Modifié(e) : Stephen23 le 8 Août 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
  1 commentaire
Triveni
Triveni le 8 Août 2016
Thank you :D

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by