Changing the ASCII sort order format?

1 回表示 (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 2 日
回答済み: Stephen23 2019 年 11 月 2 日
I use
S = orderfields(S1)
to sort order fields of strucutre array. I have 10 files named 1.jpg, 2.jpg upto 10.jpg. After using orderfiled the result is: 1.jpg, 10.jpg, 2.jpg, ...., 9.jp
I need to have 10 after 9. Any idea?

回答 (2 件)

Walter Roberson
Walter Roberson 2019 年 11 月 2 日
struct arrays cannot have fields with those names -- only table objects can have fields with those names (R2019b onwards only.) Therefore the question is not relevant. You need to sort contents not field names. I discussed how to sort contents in response to your previous related question https://www.mathworks.com/matlabcentral/answers/488816-sort-the-dir-loaded-files
  2 件のコメント
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 2 日
@ Walter Roberson Thanks a ton Walter. Why struct arrys cannot have fields with those names? I am having struct array with those names and it looks ok just having problem with their sorting style.
Stephen23
Stephen23 2019 年 11 月 2 日
"Why struct arrys cannot have fields with those names?"
The MATLAB documentation states "Field names, like variable names, must begin with a letter, can contain letters, digits, or underscore characters, and are case sensitive"
Your names start with digits (not a letter as the documentation requires) and contains a period character (not a permitted character).

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


Stephen23
Stephen23 2019 年 11 月 2 日
To sort filenames into the order that you want download my FEX submission natsortfiles:
You can find plenty of examples in the HTML help, the Mfile help, and the online description.

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by