File not found pass to next path

조회 수: 1 (최근 30일)
Rafael Freire
Rafael Freire 2011년 7월 3일
For example :
path1 =char('C:\Users\Windows\Desktop\data base\H\');
path_user1 =char('user1_');
path_exp_1 =char('_h.fid');
path_procpar =char('\procpar');
path_amostra_user1=char('PA06F9ppt','PA06F13tr12','PAJ04100tr17','subs18','tr34','tr1619');
Do a
A=strcat(path1, path_user1, path_amostra_user1, path_exp_1)
To reach the path
C:\Users\Windows\Desktop\H\user1_SAMPLES_h.fid\procpar
So, A=<6x90 char>
Then I read the procpar files with for example a text scan
for i=1:6
TEXT(i,:)=textread(A(i,:),%s’);
end
TEXT=<6x10 double>
In this case we have all the folders on my pc. If for example in the exp2 path_exp_2 =char('_hmbc.fid'); we don’t have all the folders sample only ‘PA06F9ppt' ,'PA06F13tr12'and 'PAJ04100tr17' When the textscan is going to find the path were the sample 'subs18','tr34', its give an error because in this experiment don’t have this path ??? Error using ==> textread at 167 File not found. How I can fix that and associate the name of the samples that’s exists to the values of that

채택된 답변

Titus Edelhofer
Titus Edelhofer 2011년 7월 3일
Hi,
you can use
exist(path1, 'dir')
if a folder exists and
exist(A(i,1), 'file')
to test if the file exists.
Titus

추가 답변 (1개)

Jan
Jan 2011년 7월 3일
Creating a CHAR array pads the strings with spaces, such that all have the same length:
path_amostra_user1 = char('PA06F9ppt', 'PA06F13tr12', ...
'PAJ04100tr17', 'subs18', 'tr34', 'tr1619');
Now the line containing 'tr34' has 7 trailing spaces. But I assume the filename does not have these spaces. If this is the problem, use a cell string instead.

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by