Getting rows from dataset with particular value
2 views (last 30 days)
Show older comments
Hi All,
I have a dataset 'Resturants' which has a column with title 'Name'. Now all restaurants name are different but few of them have particular string in prefix like some of them start with 'genName' and followed by something e.g. 'genNameSouthIndian', 'genNameWestLocation'.
So out of my dataset i want to grab all rows which does not have 'genName' prefix. How do i do that?
0 Comments
Accepted Answer
Kelly Kearney
on 27 Oct 2014
isgen = ~cellfun('isempty', regexp(restInfo.Name, '^genName'));
restInfo(~isgen,:)
ans =
val1 val2 Name
1 13 'coolEatery'
3 9 'Taj'
0 0 'TheVillage'
More Answers (2)
Adam
on 27 Oct 2014
I'm not too familiar with the 'dataset' structure if that is what you are using (incidentally Matlab R2014b notes this may be removed in future releases as you should use 'table' instead), but the following:
idx = ~strncmp( str, 'genName', 7 );
will give you the row indices you want if 'str' is your column in question, e.g.
str = Restaurants{:,3};
if it were the 3rd column.
Then you should just be able to use logical indexing with idx to retain only rows that do not have the 'genName' prefix in the chosen column. Again though I'm not familiar if you can do logical indexing on rows of a dataset object, but I would have thought you can.
e.g.
myRestaurants = Restaurants{ :, idx };
3 Comments
Adam
on 27 Oct 2014
That may not be correct syntax for a dataset (if that is the structure you are using), but I'm really not familiar with them enough to give a better guess at the moment. Maybe someone else can help with that last part.
Does the code prior to it work though to give you the indices to the correct rows?
See Also
Categories
Find more on Tables 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!