|
|
Read from all files in a directory with a MATLAB Script
Hello everyone,
I have a MATLAB script that reads some data from a text file and then does some calculations and writes to another file. I would like to run this script for several thousand files in the same directory that don't have very similar file names. I was wondering how you would go about doing something like this. Is there anything in MATLAB similar to the find command in linux, which allows you to run a command for every file in a directory?
Thank you!
|
|
0
|
|
|
|
Reply
|
Diana
|
3/26/2010 6:55:21 PM |
|
On Fri, 26 Mar 2010 14:55:21 -0400, Diana <diana.qiu@yale.edu> wrote:
> Hello everyone,
>
> I have a MATLAB script that reads some data from a text file and then
> does some calculations and writes to another file. I would like to run
> this script for several thousand files in the same directory that don't
> have very similar file names. I was wondering how you would go about
> doing something like this. Is there anything in MATLAB similar to the
> find command in linux, which allows you to run a command for every file
> in a directory?
>
> Thank you!
Maybe you could use ideas in:
http://www.mathworks.com/matlabcentral/fileexchange/22544-recursive-directory-walk-with-exec-unix-type
|
|
0
|
|
|
|
Reply
|
Ashish
|
3/26/2010 6:59:56 PM
|
|
"Diana " <diana.qiu@yale.edu> wrote in message
news:hoivup$n41$1@fred.mathworks.com...
> Hello everyone,
>
> I have a MATLAB script that reads some data from a text file and then does
> some calculations and writes to another file. I would like to run this
> script for several thousand files in the same directory that don't have
> very similar file names. I was wondering how you would go about doing
> something like this. Is there anything in MATLAB similar to the find
> command in linux, which allows you to run a command for every file in a
> directory?
See question 4.12 in the newsgroup FAQ. You will need to have some way
either to generate a list of the files you want to process or to determine,
given a file name, whether you want to process it.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
|
0
|
|
|
|
Reply
|
Steven
|
3/26/2010 7:03:19 PM
|
|
"Diana " <diana.qiu@yale.edu> wrote in message <hoivup$n41$1@fred.mathworks.com>...
> Hello everyone,
>
> I have a MATLAB script that reads some data from a text file and then does some calculations and writes to another file. I would like to run this script for several thousand files in the same directory that don't have very similar file names. I was wondering how you would go about doing something like this. Is there anything in MATLAB similar to the find command in linux, which allows you to run a command for every file in a directory?
>
> Thank you!
one of the solutions
d=dir('*'); % <- retrieve all names: file(s) and folder(s)
d=d(~[d.isdir]); % <- keep file name(s), only
d={d.name}.'; % <- file name(s)
nf=numel(d);
for i=1:nf
disp(sprintf('working on %5d/%5d: %s',i,nf,d{i}));
% do something, eg,
% type(d{i});
end
us
|
|
0
|
|
|
|
Reply
|
us
|
3/26/2010 7:05:05 PM
|
|
"us " <us@neurol.unizh.ch> wrote in message <hoj0h1$3c1$1@fred.mathworks.com>...
> "Diana " <diana.qiu@yale.edu> wrote in message <hoivup$n41$1@fred.mathworks.com>...
> > Hello everyone,
> >
> > I have a MATLAB script that reads some data from a text file and then does some calculations and writes to another file. I would like to run this script for several thousand files in the same directory that don't have very similar file names. I was wondering how you would go about doing something like this. Is there anything in MATLAB similar to the find command in linux, which allows you to run a command for every file in a directory?
> >
> > Thank you!
>
> one of the solutions
>
> d=dir('*'); % <- retrieve all names: file(s) and folder(s)
> d=d(~[d.isdir]); % <- keep file name(s), only
> d={d.name}.'; % <- file name(s)
> nf=numel(d);
> for i=1:nf
> disp(sprintf('working on %5d/%5d: %s',i,nf,d{i}));
> % do something, eg,
> % type(d{i});
> end
>
> us
Thank you very much!
|
|
0
|
|
|
|
Reply
|
Diana
|
3/26/2010 7:59:20 PM
|
|
|
4 Replies
304 Views
(page loaded in 0.037 seconds)
|
|
|
|
|
|
|
|
|