I have a table with some data:
clothes = table;
clothes.Type = ["Suit";"Shirt";"Dress"];
clothes.Colour = ["Blue";"Red";"White"];
clothes.Price = [300;50;400];
I want to write a filter that allows a user to define what they are interested in in each category and return the result. A simple way to do this would be:
filters = struct;
filters.Type = "Shirt";
filters.Colour = "Red";
filters.Price = 50;
f = find(strcmp(clothes.Type,filters.Type) ...
& strcmp(clothes.Colour,filters.Colour) ...
& clothes.Price == filters.Price);
output = clothes(f,:);
Suppose the user doesn't want to filter for the price and wants to see all results relevant to Red Shirts. Is there a way to write the code in such a way that when the user doesn't set any value to the filter (e.g. filters.Price = ), the find function will return all table entries with Red Shirts irrespectively of price? I thought about checking if it is empty then set the filter to contain all unique values of the relevant column of the table, but the real dataset is quite large and it's not very efficient.