Effacer les filtres
Effacer les filtres

Save in nested loop

3 vues (au cours des 30 derniers jours)
Nicolas
Nicolas le 12 Avr 2011
Hi,
I'm a bit lost concerning saving data in loops. I have a list of data that I need to analyse with several parameters.
list_files2load = dir('*.txt');
files = {list_files2load.name};
m = length(files);
for w=1:m
sprintf('loading file : %s', files{w})
s = load(files{w});
for A:1:2:20
...
for n=1:17
if... <B
if... <A
plot....
saveas(gcf,[files{w}-A-n], 'ai')
end
end
...
save('files{w}-A-n', 'data', 'ASCII')
end
end
my problem is that I would like to save the data inside the loop, something like data-1-1, then data-1-2 and so on until data-20-17, but i have no clues...
I'll appreciate any help!
cheers
n.

Réponse acceptée

Jan
Jan le 12 Avr 2011
for A:1:2:20
for n=1:17
Name = sprintf('%s-%d-%d', files{w}, A, n);
saveas(gcf, Name, 'ai')
save(Name, 'data', 'ASCII')
end
end
  3 commentaires
Nicolas
Nicolas le 12 Avr 2011
just another question.
my initial data is "data.txt" then when is create the name i got data.txt-1-1.
can I get rid of the .txt ? before creating the name?
thanks
Jan
Jan le 12 Avr 2011
File = 'data.txt'
[FilePath, FileName, FileExt] = fileparts(File)
It is always a reliable method to use absolute file names including the path. See also: help fullfile.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by