MATLAB: How to delete selected images from a folder

acess foldercell arraydeleteselected images

Hi everyone, I have a group of images and I want to delete some of them, selected by their contents.
They are all named with a progressive name (Img000001, ImgA000002 and so on…) and I have collected the numbers of the ones I want to keep in the vector 'ok' with this code:
% Image acquisition and crop
tiffFiles = dir('*.tif');
numfiles = length(tiffFiles);
cell = cell(1, numfiles);
count=0;
ok = zeros();
for k = 1:numfiles
cell{k} = imread(tiffFiles(k).name);
cell_adj{k} = imadjust (cell{k});
cell_crop{k} = imcrop (cell_adj{k}, [0,30,1616,300]);
cell_sub{k} = cell_crop{k}-cell_crop{1};
cell_2bw{k} = imbinarize(cell_sub{k}, 0.25);
if cell_2bw{k} == zeros()
cell_2bw{k} = [];
else
ok(count) = k-1;
count = count + 1;
end
end
Now I don't know how to access the folder and delete the selected files. Thank you for your help!
Monni

Best Answer

You code fails: You start with
count = 0;
ok = zeros();
and later on:
ok(count) = k-1;
count = count + 1;
Now ok(0) is accessed in the first iteration and this is an error. Incread count before using it as index.
What about this:
if cell_2bw{k} == 0
delete(tiffFiles(k).name);
end