MATLAB: How can I sort a struct

MATLABstructtable

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?

Best Answer

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)