I often find myself trying to search cell arrays like I would want to search a database with a sql query. In this case, I\'ve got a number of military bases (bases.shp)
Given the output of regexp
you can index back into the original cell array just by checking if each item in the resultant cell array is empty. You can do this using cellfun
to apply a function to each cell.
To get an array of logicals, for non-empty items you can do:
base_strings = {bases.FAC_NAME}';
ind = ~cellfun(@isempty, regexp(base_strings, 'Air Force'))
Or more cleanly using an anonymous function:
ind = cellfun(@(x)( ~isempty(x) ), regexp(base_strings, 'Air Force'))
Then, to filter:
filtered = base_strings(ind);