Sort characters w/ number in a field of struct array

7 views (last 30 days)
Capture.PNG
Hi everyone,
I am wondering what function should I use to reorgnize the name in a certain way (e.g., descending). I think "sort" function does not work here.
Thank you.
  3 Comments
Jan
Jan on 29 Dec 2018
What does "reorganize the names in a certain way" exactly mean? Which way? I guess per isakson's idea hits the point, but it is easier, if you reveal, what you want to achieve.
Cheeesepondue
Cheeesepondue on 29 Dec 2018
I wanted to sort the field of "name" in the descending order, starting from ~_1.scv to ~_end number.scv. I agree with what you said!

Sign in to comment.

Accepted Answer

per isakson
per isakson on 29 Dec 2018
Edited: per isakson on 29 Dec 2018
Search FEX for sort natural and see Natural Order Sorting

More Answers (1)

Stephen23
Stephen23 on 30 Dec 2018
Edited: Stephen23 on 18 Apr 2021
You could download natsortfiles, which now directly sorts the DIR output structure:
S = dir(..);
S = natsortfiles(S); % alphanumeric sort by filename
  1 Comment
Cheeesepondue
Cheeesepondue on 30 Dec 2018
As a beginner of MATLAB who is avidly learning lots of features, I am realizing the importance of reading through documentations. Thank you for your tip!

Sign in to comment.

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!