How do I remove all filenames from my cellarray with .m ending, if else how do I save those with .bmp?

1 view (last 30 days)
I have saved all filenames in a cell array for a given folder however, I only want it to include the files with ending .bmp.
function filer = filnamn(katalog)
%Ger en cell med de filer som finns i sökta katalog.
filer = dir(katalog);
filer = {filer(~[filer.isdir]).name};
How would I go about doing this?

Sign in to comment.

Accepted Answer

KSSV on 26 Feb 2021
idx = contains(filenames,'.bmp') ;

More Answers (1)

Stephen23 on 26 Feb 2021
Edited: Stephen23 on 26 Feb 2021
Change the DIR call to specify the file extension:
filer = dir(fullfile(katalog,'*.bmp'));
This is more efficient than getting the entire file content and then removing some names (e.g using contains).


Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!