From: Martin on
I have this code

C = cell(1, 10);
for m = 1:10
C{m} = load(sprintf('tot__r1_%03d.dat', m));
A=zeros(256);
B=C{1,m}
A(B(:,1))=B(:,2);
%here I need code that does Y(m)=A
end

I need to have 10 different output files of A, one for each m. Please, can you help?
From: ImageAnalyst on
Use sprintf() to build up a unique filename in each iteration that
depends on m or whatever else you want.

folder = 'c:\whatever';
for m = 1:10
% Your matrix code......

% Create filename.
baseFileName = sprintf('File %d', m);
fullFileName = fullfile(folder, baseFileName);

% Open file for writing.
fid = fopen(fullFileName , 'wt');

% Write out A or Y or whatever you want with fprintf()
% fprintf();

% Close this file.
fclose(fid);
end
From: dpb on
Martin wrote:
> I have this code
>
> C = cell(1, 10);
> for m = 1:10
> C{m} = load(sprintf('tot__r1_%03d.dat', m));
> A=zeros(256);
> B=C{1,m}
> A(B(:,1))=B(:,2);
> %here I need code that does Y(m)=A
> end
>
> I need to have 10 different output files of A, one for each m. Please,
> can you help?

From FAQ 4.12 (again)...

datFiles = dir('tot_r2*.dat');
for m = 1:length(datFiles)
fname = datFiles(m).name;
C{m} = load(fname);
...
[p,name,ext] = fileparts(fname);
save fullname(p [name '_A' ext]) A
end

--
From: Steven Lord on

"dpb" <none(a)non.net> wrote in message
news:i08qgu$bji$1(a)news.eternal-september.org...
> Martin wrote:
>> I have this code
>>
>> C = cell(1, 10);
>> for m = 1:10
>> C{m} = load(sprintf('tot__r1_%03d.dat', m));
>> A=zeros(256);
>> B=C{1,m}
>> A(B(:,1))=B(:,2);
>> %here I need code that does Y(m)=A
>> end
>>
>> I need to have 10 different output files of A, one for each m. Please,
>> can you help?
>
> From FAQ 4.12 (again)...
>
> datFiles = dir('tot_r2*.dat');
> for m = 1:length(datFiles)
> fname = datFiles(m).name;
> C{m} = load(fname);
> ...
> [p,name,ext] = fileparts(fname);
> save fullname(p [name '_A' ext]) A

Remember in this case to use the _function_ form of SAVE, not the _command_
form.

save( fullname(p, [name '_A' ext]), 'A')

not

> save fullname(p [name '_A' ext]) A

--
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