load some data.mat placed in different folders in loop

조회 수: 1 (최근 30일)
mausam
mausam 2014년 4월 21일
댓글: mausam 2014년 4월 21일
here is the code i use to change the current folder
%%
[pathname] = uigetdir('D:\folder1');
cd(pathname);
files = dir( fullfile(pathname,'*.mat') ); % list all *.mat files
files = {files.name}'; %# file names
%%
%-----------------------------------------------------------------
then i load the different data.mat in loop by creating separate workspace variable and perform my task on these data and get result. my problem is i have fixed task to be performed on data placed in different folders so i changes folder manually by changing path each time. for example to perform my task on data placed in 'D:/folder2' i have to change it each time and run the program.
is there a way to change current folder in loop and get all result (plot of result) at once.
since i cant place all data in a single folder

채택된 답변

per isakson
per isakson 2014년 4월 21일
편집: per isakson 2014년 4월 21일
Try something like this
folder_list = {'d:\folder1','d:\folder2','d:\folder3'};
for jj = 1 : length( folder_list )
pathname = folder_list{jj};
cd( pathname );
files = dir( fullfile( pathname, '*.mat' ) );
...
end
or there might be a cheaper way, e.g. with dir, to set folder_list.
  댓글 수: 2
Joseph Cheng
Joseph Cheng 2014년 4월 21일
Is there a reason you are changing directories? As long as you are keeping tack of the "current" folder as per isakson is suggesting you do not have to change folders
mausam
mausam 2014년 4월 21일
thank you.
it worked, and save mine lot of time and effort.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by