how can I sort a struct?

1 次查看(过去 30 天)
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 个评论
Rik
Rik 2019-11-19
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.

请先登录,再进行评论。

采纳的回答

JESUS DAVID ARIZA ROYETH
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by