how can I sort a struct?

3 ビュー (過去 30 日間)
Mira le
Mira le 2019 年 11 月 19 日
コメント済み: Rik 2019 年 11 月 19 日
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
JESUS DAVID ARIZA ROYETH 2019 年 11 月 19 日
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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by