From: Tim on
Hi,
I have 1000's of .csv files that have a poor numbering system like this:

data1
data2
.......
data99
data100
data101

and when I use the 'dir' function, it sorts then by the first digit after the word 'data.' Is there anyway to have the dir function or some other function sort by the whole value after the word data instead of 1st digit, 2nd digit, 3rd digit?
Thanks
From: Nathan on
On Feb 2, 2:46 pm, "Tim " <thu...(a)remove.this.iastate.edu> wrote:
> Hi,
> I have 1000's of .csv files that have a poor numbering system like this:
>
> data1
> data2
> ......
> data99
> data100
> data101
>
> and when I use the 'dir' function, it sorts then by the first digit after the word 'data.'   Is there anyway to have the dir function or some other function sort by the whole value after the word data instead of 1st digit, 2nd digit, 3rd digit?
> Thanks

One way:
(Assume A is your array of data file names, which all start with
'data' and are followed by numbers)
A=
{'data1';'data2';'data3';'data4';'data41';'data5';'data502';'data9';'data999'}
[ix ix] = sort(cellfun(@(x)str2double(x(5:end)),A));
A = A(ix);
%%%%%%%%%%%%%%
A
A =
'data1'
'data2'
'data3'
'data4'
'data5'
'data9'
'data41'
'data502'
'data999'

I hope this helps!

-Nathan
From: Walter Roberson on
Tim wrote:

> I have 1000's of .csv files that have a poor numbering system like this:
>
> data1
> data2
> ......
> data99
> data100
> data101
>
> and when I use the 'dir' function, it sorts then by the first digit
> after the word 'data.' Is there anyway to have the dir function or
> some other function sort by the whole value after the word data instead
> of 1st digit, 2nd digit, 3rd digit?

dirresult = dir;

%assuming that you have already eliminated any other files such as
%'.' and '..' from dir

fids = {dirresult.name}; %structure expansion!!
filenums = cellfun(@(str) num2str(str(4:end)), fids);
[sortedvals, sortorder] = sort(filenums);
sorteddir = dirresult(sortorder);
From: Tim on

> dirresult = dir;
>
> %assuming that you have already eliminated any other files such as
> %'.' and '..' from dir
>
> fids = {dirresult.name}; %structure expansion!!
> filenums = cellfun(@(str) num2str(str(4:end)), fids);
> [sortedvals, sortorder] = sort(filenums);
> sorteddir = dirresult(sortorder);

Thanks for your help thus far...
That worked for the 'data###' files. I also have some that have numbers like this :

14791 01 010_1_1.spc
14791 01 010_2_1.spc
14791 01 010_3_1.spc
......
14791 01 010_9_1.spc
14791 01 010_10_1.spc
.....
14791 01 010_195_1.spc
14791 01 010_196_1.spc

14791 01 010_1166_1.spc
14791 01 010_1167_1.spc

any help with these?
Thanks
From: us on
"Tim " <thurst(a)remove.this.iastate.edu> wrote in message <hka9va$r2h$1(a)fred.mathworks.com>...
> Hi,
> I have 1000's of .csv files that have a poor numbering system like this:
>
> data1
> data2
> ......
> data99
> data100
> data101
>
> and when I use the 'dir' function, it sorts then by the first digit after the word 'data.' Is there anyway to have the dir function or some other function sort by the whole value after the word data instead of 1st digit, 2nd digit, 3rd digit?
> Thanks

you may find this utility, which comes with a template option, useful...

http://www.mathworks.com/matlabcentral/fileexchange/7212

us
 |  Next  |  Last
Pages: 1 2
Prev: displaying image in axes
Next: Catching Java exception