====== filterTracks.m ====== **Class:** Function **Description:** Finds all tracks with mean feature values (averaged across time) that exceed a user-specified value. User can specify whether tracks with mean feature values that fall below or above this threshold are removed. **Author:** Oliver J. Meacock function procTracks = filterTracks(procTracks,filterField,filterVal,filterDir) %FILTERTRACKS removes tracks with mean feature values that exceed a %user-specified threshold. % % INPUTS: % -procTracks: The main track output of FAST's tracking module % -filterField: String specifying a feature field you wish to use as % a filter (e.g. 'vmag','sparefeat1' etc) % -filterVal: The value that should not be exceeded for a given track % to remain under consideration. % -filterDir: Whether you wish to remove tracks below (-1) or above % (+1) the specified threshold value. % % OUTPUTS: % -procTracks: The set of processed tracks, with tracks that exceed % the specified threshold removed. % % Author: Oliver J. Meacock, (c) 2021. meanVals = arrayfun(@(x)(nanmean(x.(filterField))),procTracks); switch filterDir case +1 badInds = meanVals > filterVal; case -1 badInds = meanVals < filterVal; end procTracks(badInds) = []; **Example usage:** %Extract and plot mean intensity of each object in channel 1 meanInts = arrayfun(@(x)(nanmean(x.channel_1_mean)),procTracks); histogram(meanInts,'BinWidth',5) hold on %Remove all objects that have a channel 1 intensity that exceeds this threshold procTracks = filterTracks(procTracks,'channel_1_mean',60,+1); %Repeat intensity measurement and plotting meanInts = arrayfun(@(x)(nanmean(x.channel_1_mean)),procTracks); histogram(meanInts,'BinWidth',5) **Example output:** After filtering, all tracks with average channel 1 intensities greater than 60 have been removed: {{ :post:fluofilterdemo.png?600 |}}