MATLAB: Searching values in a dataset

dataseteq operatorfiltersearch datasetundefined eq operator dataset

Hi
I need to apply some filters to a dataset, or just look for some specific quantity. However, I receive an error that the eq operator is not defined for datasets. I know I can convert a particular column to, e.g., double and then use the eq operator for double, but if the dataset is big, I am concerned about performance overheads due to constant conversions.
So
  • Is there any way to apply a filter to a dataset without converting it first to other type (e.g., double)?
  • Is there any way to look for values in specific columns of a dataset without converting such column first to other type (e.g., double)?
Thanks in advance

Best Answer

Quite often, this is the kind of thing you'd do to pick out rows of a dataset array:
>> load hospital
>> hospital(hospital.Age>45 & hospital.Sex=='Male',{'LastName' 'Age' 'Smoker'})
ans =
LastName Age Smoker
KOQ-996 'MARTIN' 48 true
XBA-581 'ROBINSON' 50 false
YYV-570 'SCOTT' 47 false
FLJ-908 'STEWART' 49 true
DAU-529 'REED' 50 true
FCD-425 'GONZALES' 48 false
MEZ-469 'GRIFFIN' 49 false
ZZB-405 'HAYES' 48 false
There's not really any need to explicitly "convert" Age to double, just by subscripting using dot, you get back the Age variable itself. Similarly for the Sex variable. Performance wise, this is actually (under the hood) a shared copy of something that already exists, so it should be fast.