Open multiple files in different sub-folders with same starting file name

조회 수: 2 (최근 30일)
Damith
Damith 2014년 5월 22일
댓글: Image Analyst 2014년 5월 22일
Hi,
I have a multiple files I need to read in 39 sub-folders in Home directory. For example:
Home\folder1\Output_1 Home\folder2\Output_2 .. Home\folder39\Output_39
What is the MATLAB function I can use to open all the sub-folders so that I can use importfile function to read all Output files from 1 to 39.
Thanks in advance for the help.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 22일
편집: Azzi Abdelmalek 2014년 5월 22일
for k=1:39
f=sprintf('Home\\folder%d\\output_%d',k,k)
% read f
end
  댓글 수: 2
Damith
Damith 2014년 5월 22일
I did the following but it returns nothing and gives an error message. (See below). Sub_folder name are Pts001, Pts002,...upto Pts0039 so I modified your code. In each sub-folder file names are Output_1, Output_2....upto Output_39. There is no value in f.
addpath('C:<path>\Generated_39');
for k=1:39 f=sprintf('Pts%d\output_%d',k,k); end
Warning: Escape sequence 'o' is not valid. See 'help sprintf' for valid escape sequences.
Thanks,
Image Analyst
Image Analyst 2014년 5월 22일
Notice how you use a single backslash and Azzi used a double backslash? It makes a difference. But why not just use a single forward slash instead? It works just fine in Windows - Windows does not require backslashes.

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

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by