With a geographical grid the size 20x30, I have two (temperature) variables:
The data A
with the size 20x30x100
and a threshold
the size 20x30
I'd like to apply the threshold to the data, i.e. to cut out the values in A
that are above threshold
, with every grid point having its own threshold. Since that will give a different number of values for each grid point, I thought to pad the rest with zeros, so that the resulting variable, let's call it B
, will also be of the size 20x30x100.
I was thinking to do something like this, but there's something wrong with the loop:
B = sort(A,3); %// sort third dimension in ascending order
threshold_3d = repmat(threshold,1,1,100); %// make threshold into same size as B
for i=1:20
for j=1:30
if B(i,j,:) > threshold_3d(i,j,:); %// if B is above threshold
B(i,j,:); %// keep values
else
B(i,j,:) = 0; %// otherwise set to zero
end
end
end
What is the correct way to do the loop?
What other options to do this are there?
Thanks for any help!