tresholding by summing over a dimension of a matrix

1 view (last 30 days)
I am trying to treshold data by summing over elemtns in the third dimension of a matrix and if the sum of all elements in a row of the third dimension is larger than a treshold value, all that row is set to NaN. However, I think the code I wrote must not be doing what I think it is since it is taking a very long time to compile.
Could you help me write some code please?
for c = 1:200000
for b = 1:32
for a= 1:32
if sum(micron_62frames(a,b,:),3) > 200000*65
micron_62frames(a,b,:) = NaN;
elseif sum(micron_62frames(a,b,:),3) < 200000*65
micron_62frames(a,b,:) = micron_62frames(a,b,:);
David Goodmanson
David Goodmanson on 25 Nov 2019
Also the elseif statement and the command that goes with it is unneccesary, since all you are doing with
micron_62frames(a,b,:) = micron_62frames(a,b,:)
is setting a bunch of stuff equal to what it is already.

Sign in to comment.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 27 Nov 2019
k = size(micron_62frames,3);
lo = sum(micron_62frames,3) > 13e6;
micron_62frames(repmat(lo,1,1,k)) = nan;

Community Treasure Hunt

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

Start Hunting!