Effacer les filtres
Effacer les filtres

how can I sort a struct?

2 vues (au cours des 30 derniers jours)
Mira le
Mira le le 19 Nov 2019
Commenté : Rik le 19 Nov 2019
my struct is declared as:
chr.id=[];
chr.sequence=[];
chr.Si={};
chr.relevant=[];
chr.vic_item = [];
len=numel(x);
TI=repmat(chr,len);
and then, TI will fill with value
after that I want to sort TI in descending order,
How do we do that?
  1 commentaire
Rik
Rik le 19 Nov 2019
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.

Connectez-vous pour commenter.

Réponse acceptée

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH le 19 Nov 2019
solution:
x=1:5;%put your x here
chr.id=[];
chr.sequence=[];
chr.Si={};
chr.relevant=[];
chr.vic_item = [];
len=numel(x);
TI=repmat(chr,len,1);
%fill example random :
for k=1:numel(x)
TI(k).id=rand;
end
TItemp=sortrows(struct2table(TI),'id'); %sort by id
TIsorted=table2struct(TItemp);
disp(TItemp)

Plus de réponses (0)

Catégories

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

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by