How to select cells that meet a threshold based on a starting point

1 view (last 30 days)
Hi,
I have a matrix (DFF) that is 370x23, in this instance, that has my signal values from a video. The 370 is the number of frames, and the 23 is the number of ROIs I designated. I am trying to designate the significant signals based on 3 criteria:
  1. the signals start with a derivative that is 2.5*stdnoise i.e. is significant
  2. After this, the rest of the signal is greater than 2.5*sigma (noise) above mu (baseline) i.e. 2.5*sigma>mu
  3. if there is no signal after the derivative, it short circuits and the first criteria is not met
The derivative part usually ID's 1 or 2 cells, and then the rest of the signal is the cells that follow this. The problem is that I don't know how to combine these criteria so that the code identifies the first derivative and then applies the second criteria to only those cells that follow a significant first derivative.
I have code written for the first part, the derivative part and it works fine (note the output is a logical array called raster of the same size as DFF):
difDFF=diff(DFF)
numcells = size(DFF,2);
emptyrow = zeros(1,numcells);
difDFF = [emptyrow;difDFF];
rasterSig = find(raster);
difDFFnoise = difDFF;
difDFFnoise(rasterSig) = NaN;
stdnoise = nanstd(difDFFnoise);
sigthresh = 2.5 .* stdnoise;
significantTransients = difDFF - sigthresh
significantTransients(significantTransients>0) = 1;
significantTransients(significantTransients<=0) = 0;
rasterNotSig = find(~raster);
significantTransients(rasterNotSig) = 0
But I can't figure out how to restrict applying the second criteria to only those signals that start with a significant first derivative. This is the code that would perform the function described in criteria 2, but not restricted:
signalthreshold=2.5 .* sigma;
signalthreshold=repelem(signalthreshold,size(DFF,1),1)
significantsignal=DFF-signalthreshold;
significantsignal(significantsignal>mu)=1;
singificantsignal(significantsignal<=mu)=0;
So, is there any way to combine these two criteria and limit the second one to only those signals whose first derivative is significant, as defined in the first bit of code here? Also, I could take or leave the third criteria, because I think I could figure out how to write that once I know how to combine the first and second.
Please help, and thanks for your consideration.
  1 Comment
ARP
ARP on 13 Apr 2020
I woul recomend to use the else / elseif condition. Make your flow chart and practice with known answers. Hope it helps

Sign in to comment.

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!