From: Khanh on
Walter Roberson <roberson(a)hushmail.com> wrote in message <tOV8o.48958$F%7.14351(a)newsfe10.iad>...
> Khanh wrote:
> > Walter Roberson <roberson(a)hushmail.com> wrote in message
> > <i3skm9$c6q$4(a)canopus.cc.umanitoba.ca>...
> >> dpb wrote:
> >> > Khanh wrote:
> >> >> So I have some files that I want to read all with 'sprintf'. If
> >> those >> files are named test1.txt, test2.txt, test3.txt... then I
> >> have no >> problem using for k=1:n
> >> >> sprintf('c:/folder/test%d.txt',k)
> >> >>
> >> >> But if my files are name like text_0001.txt, text_0002.txt, and so
> >> on, >> I have not figured out away to use sprintf function to read
> >> those files.
> >> >> Any suggestions?
> >> > > doc dir
> >>
> >> sprintf('C:/folder/test%04d.txt',k)
> >
> > this does not solve the problem. How can you make it skip the "_" and
> > all the zeroes.
> > If the text file goes up to like text_0012.txt, ...text_0112.txt,...
>
> Sorry, make that
> sprintf('C:/folder/test_%04d.txt',k)
>
> And if that isn't a sufficient answer to your question, then I would
> question how it is that you expect a function that formats strings for
> output to be able to *read* files.
>
> Have you considered dir('C:/folder/test_*.txt') ?

Here is my program
clear
clc
numb_run=1;
for k=1:100%100 folders i.e. RUN_00001....RUN00100%
filename = sprintf('H:/Summer 10/Sootformation/nheptane/RUN_%d/closed_homogeneous__ignition_delay.out', k);
fid=fopen(filename);
for i=1:1:400
tline=fgetl(fid);
if strfind(tline,'c2h2')==41
linumb=i;
a=textscan(tline,'%s = %f %s = %f %s = %f');
if a{4}~=0
mf(numb_run)=a{4};
numb_run=numb_run+1;
end
end
end
fclose(fid);
end
col_mf=mf';

Still not working.
From: Walter Roberson on
Khanh wrote:

> Here is my program
> clear
> clc
> numb_run=1;
> for k=1:100%100 folders i.e. RUN_00001....RUN00100%
> filename = sprintf('H:/Summer
> 10/Sootformation/nheptane/RUN_%d/closed_homogeneous__ignition_delay.out',
> k);

Well of course if you keep changing the rules of the game then you can't
expect my solutions to work without adjustment. Your question before had
to do with filenames that had 4 digits after the "_" and I suggested
using %04d . Now that your filenames have 5 digits after the "_" the
solution is to use %05d instead of just %d .

> fid=fopen(filename);

Why aren't you testing to be sure that the open succeeded?

> for i=1:1:400
> tline=fgetl(fid);
> if strfind(tline,'c2h2')==41
> linumb=i;
> a=textscan(tline,'%s = %f %s = %f %s = %f');

If you are doing a simple scan of a string with no change to default
Whitespace or Delimiter or CommentStyle or the like, then you might as
well use sscanf() instead of textscan .

> if a{4}~=0

Assuming there _is_ an a{4} if the file isn't corrupted ...

> mf(numb_run)=a{4};
> numb_run=numb_run+1;
> end
> end
> end
> fclose(fid);
> end
> col_mf=mf';
>
> Still not working.
From: Khanh on
First of all, please calm down :P and thank you for your suggestions.
Secondly, I tried the method you mentioned even before you suggesting me, so no, it doesn't work, that's why I still need help. Have you had time to try and see it yourself? Yes, I used %05d or %04 for 5 digits and 4 digits whatsoever.

I used "fid=fopen(filename)" just to put variable name for the opened file.
From: Steven_Lord on


"Khanh " <kdcung(a)mtu.edu> wrote in message
news:i41eso$6kl$1(a)fred.mathworks.com...
> First of all, please calm down :P and thank you for your suggestions.
> Secondly, I tried the method you mentioned even before you suggesting me,
> so no, it doesn't work, that's why I still need help.

Can you clarify what you mean when you say "it doesn't work"?

Does it throw a warning, and if so what is the exact text of the warning?
Does it throw an error, and if so what is the exact text of the error?
Does it give you the wrong answer, and if so describe in more detail what
answer you receive and what answer you expected?
Does it do something else, and if so what?

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: dpb on
Khanh wrote:
....

> filename = sprintf('H:/Summer
> 10/Sootformation/nheptane/RUN_%d/closed_homogeneous__ignition_delay.out',
> k);

rd = 'H:/Summer 10/Sootformation/nheptane/'
d = dir([rd 'RUN*closed_homogeneous__ignition_delay.out'])
for idx = 1:length(d)
fid=fopen(d.name);
....
% whatever w/ files here
fclose(fid);
end


doc dir

--