How can I make imageDatastore sort naturally?
Mostrar comentarios más antiguos
When I use imageDatastore to store files, the files are sorted according to their names like so:

This is how MATLAB sorts them by default. How can I make it store the files in an image datastore in the correct order ('1,5,10,15,20' rather than '1,10,15,20,5')? Or is there a way to create a new datastore with the sorted filenames? I understand that sort_nat or natsortfiles could be used in some way, but I'm not sure how. I can't sort and store the images in any other way(like in a table or directory), it has to be an image datastore.
Respuesta aceptada
Más respuestas (1)
yanqi liu
el 8 de Oct. de 2021
3 votos
sir,may be use the 001、002、…… as image filename
3 comentarios
Pranay Koppula
el 8 de Oct. de 2021
Stephen23
el 8 de Oct. de 2021
@Pranay Koppula: actually, if you use sufficient leading zeros then sorting by character does resolve this problem, exactly as yanqi liu writes. This is a robust and very efficient solution.
Pranay Koppula
el 9 de Oct. de 2021
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!