Hello,
I have a problem with saving files in different paths and I am very thankful for your help.
Suppose there is a fix path:
path = 'D:\folder_1\folder_2';
If I wanna save a data set in the same path I would write:
save(fullfile(path,'FILE_NAME.MAT'));
However, base upon each data set I need to save them in different subfolders of folder_2 such as dataset_1 in folder_2A, dataset_2 in folder_2B, etc. Note that the base PATH is always the same. How can I do that?
Thanks so much :)

 채택된 답변

Arnaud Miege
Arnaud Miege 2011년 5월 26일

2 개 추천

Something like that should do:
base_path = 'D:\folder_1\folder_2';
% You can also use dir to get the list of the subfolders
subfolder{1} = 'folder_2A';
subfolder{2} = 'folder_2B'; % etc...
fname{1} = 'dataset_1.mat';
fname{2} = 'dataset_2.mat'; % etc...
for k = 1:length(subfolder)
save(fullfile(base_path,subfolder{k},fname{k}));
end
HTH,
Arnaud

댓글 수: 6

M G
M G 2011년 5월 27일
Thanks a lot Arnaud.
Walter Roberson
Walter Roberson 2018년 5월 5일
If there is a pattern to fname entries then you can compute them. For example, for folder_1A folder_1B folder_2A folder_2B ...
for K = 1 : ...
series = floor((K-1)/2) + 1; %1,1,2,2,3,3,...
AB = char('A' + mod(series-1,2)); %ABAB
this_folder = sprintf('folder_%d%s', series, AB);
...
end
AMBIKA P S
AMBIKA P S 2018년 5월 5일
Thanks a lot sir !
AMBIKA P S
AMBIKA P S 2018년 5월 5일
편집: AMBIKA P S 2018년 5월 5일
The following code creates a matfile inside a folder of folder.
But, How to save a vector into the output_1.mat file?
I have a vector formed inside a loop which I should save as output_1.mat
How to do that?
for s=1:length(subfolder) % 2 here
for ss=1:length(subsubfolder) % 7 here
for sss=1:length(a) %20 here
fname{sss} = sprintf('output_%d.mat',a(sss));
ffname{sss} = sprintf('feat_%d.mat',a(sss));
save(fullfile(base_path,subfolder{s},subsubfolder{ss},fname{sss}),out);
save(fullfile(base_path,subfolder{s},subsubfolder{ss},ffname{sss}),Feat);
end
end
end
Walter Roberson
Walter Roberson 2018년 5월 5일
save( fullfile( base_path, subfolder{s}, subsubfolder{ss}, 'output_1.mat'), 'YourVectorNameGoesHereAsAString');
AMBIKA P S
AMBIKA P S 2018년 5월 6일
Thank you !

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

제품

태그

질문:

M G
2011년 5월 26일

댓글:

2018년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by