How can i save my result in each different files using FOR?

4 vues (au cours des 30 derniers jours)
MichaelK Kim
MichaelK Kim le 24 Jan 2011
Hi, I trying to save my results in each files using FOR. Total 364 files have to be modified in m.files and the modified variables have to be saved in each varibles or each files without extra modifying.
and the file names is Proj_00001.raw, Proj_00002.raw, Proj_00003.raw, ... , Proj_00363.raw and then after modifying, i want to save my result. the name of my result files will be H1.mat, H2.mat, H3.mat, H4.mat, ..., H363.mat. OR i have to save my result using 'dicomwrite' such as H1.dcm, H2.dcm, H3.dcm,...
Summary!
Proj_00000.raw file have to save at H1.mat or H1.dcm after modification
Proj_00001.raw file have to save at H2.mat or H2.dcm after modification
Proj_00002.raw file have to save at H3.mat or H3.dcm after modification
...
Proj_00363.raw file have to save at H1364.mat or H3641.dcm after modification
this is my code.
for k=1:364
filelist = dir('D:\CMC\Matlab\Projections_Head\*.raw');% call the file list
fname = filelist(k).name;
fid = fopen(fname,'r');
A = fread(fid);
for i = 0:1:767
for j = 0:1:1023
P(1+i,j+1) = 'equation for modification: P is 768x1024 double';
end
end
for s=1:364 %%this is not working at all..
slist = strcat(num2str(s));
sname = strcat('H',slist,'.mat');
savefile = (sname);
save(savefile, P);
end
end
it seems like 'fine'. but there are an error!!
??? Error using ==> save Argument must contain a string.
what am i supposed to do? or write? thank you for helping me. :)
  3 commentaires
MichaelK Kim
MichaelK Kim le 24 Jan 2011
did you applied the second FOR loop in your computer?
i mean the FOR s=1:364, this is 4th loof. it isn't working!! yes! there are an error...
Walter Roberson
Walter Roberson le 25 Jan 2011
Why are you saving the same data to each of the files ??

Connectez-vous pour commenter.

Réponses (1)

Michael Katz
Michael Katz le 24 Jan 2011
Try:
save(savefile,'P');
The second argument to SAVE should be the variable's name, not it's value.
  2 commentaires
MichaelK Kim
MichaelK Kim le 25 Jan 2011
hmm., i've change my code according to your solution. but why my matlab keep busy for over 20min... so deperate situation :(
Jan
Jan le 26 Jan 2011
So it would be helpful, if you show us what 'equation for modification: P is 768x1024 double' means in detail.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by