From: us on
"Martin " <nikolom(a)gmail.com> wrote in message <i05ub0$ll0$1(a)fred.mathworks.com>...
> I think I have figured out how to read all 999 files. I can process them in a do loop. The final step is to figure out how to automate generating 999 files containing the output. My input file names are tot_001 through tot_999. After I generate the output (a square matrix), how do I assign each output to file names Y_001 through Y_999?
>
> Thank You!

last hint...
afterwards, you really should read the getting started doc...

help save; % <- look at the function form in combination with SPRINTF...

us
From: dpb on
Martin wrote:
....[top posting repaired..don't; makes follow conversation hard]...
> "us " <us(a)neurol.unizh.ch> wrote in message
> <i05c5k$c67$1(a)fred.mathworks.com>...
>> "Martin "
>> > I was wondering how I could automate this task. I have 1000 files
>> like file B (tot_000.dat, tot_001.dat, and so forth). What would be a
>> simple way to load each file, do the matrix creation, and output it to
>> a new file? Thank You!
>>
>> a hint:
>>
>> http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_process_a_sequence_of_files.3F
>>
>>
>> us
> I did
>
> for k=1:9
> load(sprintf('/data/tot_00%d.dat',k));

Reread the FAQ above and note particularly towards the bottom the 'dir'
solution is _so_ much cleaner...and a little thought should see how that
might apply to the output side as well, I'd think. :)
--
From: Martin on
dpb <none(a)non.net> wrote in message <i05vek$5q3$1(a)news.eternal-september.org>...
> Martin wrote:
> ...[top posting repaired..don't; makes follow conversation hard]...
> > "us " <us(a)neurol.unizh.ch> wrote in message
> > <i05c5k$c67$1(a)fred.mathworks.com>...
> >> "Martin "
> >> > I was wondering how I could automate this task. I have 1000 files
> >> like file B (tot_000.dat, tot_001.dat, and so forth). What would be a
> >> simple way to load each file, do the matrix creation, and output it to
> >> a new file? Thank You!
> >>
> >> a hint:
> >>
> >> http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_process_a_sequence_of_files.3F
> >>
> >>
> >> us
> > I did
> >
> > for k=1:9
> > load(sprintf('/data/tot_00%d.dat',k));
>
> Reread the FAQ above and note particularly towards the bottom the 'dir'
> solution is _so_ much cleaner...and a little thought should see how that
> might apply to the output side as well, I'd think. :)
> --

I certainly don't mind reading the FAQ. If it were clearly written with good examples, I would not need to ask here. The paragraph that I think you refer me to is

If instead you want to process all the files whose name matches a pattern in a directory, you can use DIR to select the files. Note that while this example uses *.jpg as the pattern and IMREAD to read in the data, as with the previous example you could use whatever pattern and file reading function suits your application's needs:

jpegFiles = dir('*.jpg');
for k = 1:length(jpegFiles)
filename = jpegFiles(k).name;
data1 = imread(filename);
end

I really do not see how this will help me generate output files y_001 through y_999 within the k=1:number_of_files loop where the preceding part of the code within the loop loads input files tot_001 through tot_999, does a simple conversion and generates the output files
From: Martin on
"us " <us(a)neurol.unizh.ch> wrote in message <i05uo5$i38$1(a)fred.mathworks.com>...
> "Martin " <nikolom(a)gmail.com> wrote in message <i05ub0$ll0$1(a)fred.mathworks.com>...
> > I think I have figured out how to read all 999 files. I can process them in a do loop. The final step is to figure out how to automate generating 999 files containing the output. My input file names are tot_001 through tot_999. After I generate the output (a square matrix), how do I assign each output to file names Y_001 through Y_999?
> >
> > Thank You!
>
> last hint...
> afterwards, you really should read the getting started doc...
>
> help save; % <- look at the function form in combination with SPRINTF...
>
> us

I do not mind reading the FAQ's. I googled this with little success. I have several Matlab handbooks which are useless since they teach only the simple stuff. But this from FAQ did not help

If instead you want to process all the files whose name matches a pattern in a directory, you can use DIR to select the files. Note that while this example uses *.jpg as the pattern and IMREAD to read in the data, as with the previous example you could use whatever pattern and file reading function suits your application's needs:

jpegFiles = dir('*.jpg');
for k = 1:length(jpegFiles)
filename = jpegFiles(k).name;
data1 = imread(filename);
end

I gather the trick is to combine SPRINTF with some kind of print function like FPRINTF?
Can I do that even for a square matrix output?
From: dpb on
Martin wrote:
....

> I really do not see how this will help me generate output files y_001
> through y_999 within the k=1:number_of_files loop where the preceding
> part of the code within the loop loads input files tot_001 through
> tot_999, does a simple conversion and generates the output files

You really can't see a generalization of having the root name and making
a slight mod to that to create an output file during the loop????


--
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: china
Next: automatic gain control