How can I extract table rows based on the value of a single column

10 views (last 30 days)
William Garrett
William Garrett on 10 Nov 2019
Edited: dpb on 30 Dec 2019
I am trying to extract data from a table. My table includes air quality data from a number of sensors and I want to compare the results for when a filter was on or off.
The table headings and a line of sample data is shown below.
'Date_Time' , 'PM2.5', 'UV_BC', 'Blue_BC', 'Green_BC', 'Red_BC', 'IR_BC', 'Particle_Count' , 'Particle_Conc', 'Filter_on_off'
09-10-2019 10:50:00 3 538 398.300 364.9 375.5 935.6 155.4708 51.9907 0
The 'Filter_on_off' value ranges from 0 to 1 but is not a logistical value, values of 0.5 and 0.75 are possible (related to fan speed)
How would I isolate data when the filter is off ('Filter_on_off' = 0) and on ('Filter_on_off' >1) for comparison?
  5 Comments
dpb
dpb on 30 Dec 2019
Create a variable with the desired categories and populate it by sorting into proper category each value. A histogram would be easy way of assigning bin numbers if the speeds can be anything between 0-1.
OTOH, if they are a finite number of set speeds like those above, then simply categorical(fanspeed) will do it for the categories in unique(fanspeed)(*) You can then either use those values as the category names or assign others like 'OFF', 'SLOW','MEDIUM','HIGH' or whatever you wish.
Again, I can't urge you enough to read the documentation on categorical arrays and look at examples. varfun and/or splitapply are your friends for all these kinds of things...they all just drop in your lap if you set it up to use the facilities TMW provides.
(*) If there aren't all possible categories in the dataset, use the optional inputs to the function to define them.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!