listbox, filtering with 2 conditions

I want to filter files that I read into a list box. I am currently filtering depending if they contain red.tiff.
ImageFiles = dir([folder '\*red.tif*']);
How can I combine another filter together with this one. Depending on the users choice (either C1, C2, C3), I want only those files that contain red.tiff AND e.g. contain the C1 in their filenames.
can I use: ImageFiles = dir([folder '\*C1*red.tif*']);

1 Comment

Just to add, the user define String i also want to filter for is obtained from the user via uipanel with radio buttons on i.e.:
switch strCM
case 'rbCM1'
CM='C1'
case 'rbCM2'
CM='C2'
case 'rbCM3'
CM='C3'
case 'rbCM4'
CM='C4'
case 'rbCM5'
CM='C5'
case 'rbCM6'
CM='C6'
Not sure how to include the String CM into the filter requirement

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 23 Sep 2014
Edited: Geoff Hayes on 23 Sep 2014
Jason - just use sprintf to include CM in the filter
filenameFilter = sprintf('*%s*red.tif*',CM);
ImageFiles = dir(fullfile(folder,filenameFilter));
If CM is 'C6', then
filenameFilter =
*C6*red.tif*
The fullfile function builds the string that includes the folder path and filename filter, inserting platform-dependent file separators where necessary (so that you don't have to worry about them).

Categories

Asked:

on 23 Sep 2014

Edited:

on 23 Sep 2014

Community Treasure Hunt

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

Start Hunting!