what is the output type of a nagative fullfill function result
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Nidhal Bouzouita
am 9 Nov. 2021
Kommentiert: Jan
am 10 Nov. 2021
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"
Akzeptierte Antwort
Jan
am 9 Nov. 2021
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 Kommentare
Jan
am 10 Nov. 2021
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!