필터 지우기
필터 지우기

what is the output type of a nagative fullfill function result

조회 수: 1 (최근 30일)
Nidhal Bouzouita
Nidhal Bouzouita 2021년 11월 9일
댓글: Jan 2021년 11월 10일
Hi Guys
I am using the fullfill function as followig :
dat_dir = fullfile(uigetdir ('select the subfolder for dat file'), '*.txt' );
if convertCharsToStrings(dat_dir) ~= " \*.txt"
dat= dir(dat_dir);
end
this will help me in other way , if i did not select the subfolder , to check the result of fullfile(uigetdir ('select the subfolder for dat file'), '*.txt' ) which i found \*.txt .
The problem in other words , i found that convertCharsToStrings(dat_dir) in the workspace is equal to " \*.txt" but when i debug it i found it is not equal to " \*.txt".
this is the error msg
Error using dir
Invalid path. The path must not contain a null character.
How should i test the negative result of fullfile function ? And why the if convertCharsToStrings(dat_dir) == " \*.txt" is return 0 although i can see in the workspace convertCharsToStrings(dat_dir) equal to " \*.txt"

채택된 답변

Jan
Jan 2021년 11월 9일
What is the purpose of the leading space in " \*.txt"?
What does "if i did not select the subfolder" mean? Which subfolder? Do you mean, that you press 'Cancel' in the dialog? Then uigetdir() does not reply a space, but a numerical 0. Do not use a 0 as input for fullfile.
folder = uigetdir('select the subfolder for dat file');
if ~ischar(folder) % User pressed the Cancel button
folder = cd; % Is this wanted? Or: return?
end
dat = dir(fullfile(folder, '*.txt'));
Does this work as wanted?
  댓글 수: 3
Nidhal Bouzouita
Nidhal Bouzouita 2021년 11월 9일
maybe to just modify it as following
folder = uigetdir('select the subfolder for dat file');
if ischar(folder) % User pressed the Cancel button
dat = dir(fullfile(folder, '*.dat')); % Is this wanted? Or: return?
end
there any cons ?
Jan
Jan 2021년 11월 10일
in the above code ~ischar(folder) means the user did not press ok
Yes, if the user presses "Cancel", uigetdir replies a numerical 0.
The code of your former comment looks fine. Then dat remains undefined, if the user has pressed cancel. If you care for this case, the code should run.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by