フィルターのクリア

Sorting a structure using Matlab2018

3 ビュー (過去 30 日間)
Shamsuddeen Abdullahi
Shamsuddeen Abdullahi 2019 年 5 月 29 日
回答済み: Jan 2019 年 5 月 29 日
Hi
I want to sort this structure in descensind order using MATLAB 2018:
ten.cat=[7,2,4,1].
I used the following commands but it is still not sorted:
pp_1=ten;
TT = struct2table(pp_1) % convert to tables
gg=sortrows(TT,'cat') % sort
sortedpp_1 = table2struct(gg) % convert the table back to structure.
please, help
  3 件のコメント
Guillaume
Guillaume 2019 年 5 月 29 日
@Jan, this should go as an answer as I see no way of improving on that with the information given.
@shamsuddeen, there's never any need to convert a structure to anything in order to operate on it. Certainly, converting a structure into a table and back is a complete waste of time for your purpose. In this case, the fact that ten is a structure is completely irrelevant anyway, you're not sorting a structure, but just one field of a scalar structure which is the same as any non-structure variable.
Shamsuddeen Abdullahi
Shamsuddeen Abdullahi 2019 年 5 月 29 日
Thank u. it works

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 5 月 29 日
ten.cat = [7,2,4,1];
ten.cat = sort(ten.cat)

その他の回答 (1 件)

Simon Mählkvist
Simon Mählkvist 2019 年 5 月 29 日
編集済み: Simon Mählkvist 2019 年 5 月 29 日
Hi,
Adjusting:
ten.cat=[7,2,4,1]
to:
ten.cat=[7;2;4;1]
gives what I think is the sought after results.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by