MATLAB: How to check if a folder exists which has a variable name

dynamic folderexistfolderMATLABmkdirname

Hi,
I want to check if the created folder already exists. But the name of the folder depends on the file I work with.
fname = Measurement_20190829_18_15_10.bin
if ~exist('Figures' fname(11:end-4), 'dir')
mkdir('Figures', fname(11:end-4));
end
I have no clue how to make this work.
I always get Invalid expression with a marker on fname.
Please help.
Thank you!

Best Answer

[~,name] = fileparts(fname);
exist(fullfile('Figures',name), 'dir')~=7
Note that exist does NOT return a boolean value, it returns different integers for specific object types. It is strongly recommended to test for the specific integer that is returned for the specific object type that you are trying to locate.