Save in nested loop

조회 수: 5 (최근 30일)
Nicolas
Nicolas 2011년 4월 12일
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.

채택된 답변

Jan
Jan 2011년 4월 12일
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
Nicolas
Nicolas 2011년 4월 12일
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 2011년 4월 12일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by