How do i sort csv file in righ order??

I have csv folder that contain 1-20 csv file like 1.csv,2.csv...20.csv. How to sort all those files?? 1.csv 2.csv 3.csv ... 20.csv But in MATLAB i got the files in a different way. like 1.csv 10.csv 11.csv what is the solution

3 Comments

What was your edit? Whatever it was, your current question does not change my answer below.
Thanks :)
Stephen23
Stephen23 on 21 Sep 2018
Edited: Stephen23 on 21 Sep 2018
"what is the solution": download my FEX submission natsortfiles:

Sign in to comment.

Answers (2)

Of course the best solution is to just create the files with the proper filename to begin with, like 01.csv, 2.csv, etc.
But if you can't (like you're not the person creating the files), see this link: https://blogs.mathworks.com/pick/2014/12/05/natural-order-sorting/

2 Comments

Stephen23
Stephen23 on 21 Sep 2018
Edited: Stephen23 on 21 Sep 2018
How many leading zeros do "proper" filenames have?
As many as needed, of course! :)

Sign in to comment.

A) Don't name them that way..use
>> num2str([1:3].','%03d.csv')
ans =
3×7 char array
'001.csv'
'002.csv'
'003.csv'
>>

Categories

Asked:

on 21 Sep 2018

Commented:

dpb
on 21 Sep 2018

Community Treasure Hunt

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

Start Hunting!