MATLAB: Using for loop to calculate percentiles over a time series

for loop

Hi,
I have a dataset (DIS) that has the following dimensions (27,23,360). I could use some help in using a for loop and how to tackle the problem below.
So I want to calculate the percentile (Q90), which represents a treshold, of each element over the 3rd dimensions. And then present in a new array (27,23) the percentage of points that fall below this treshold.
So I first did this for the element in the first row and column to get an idea how I can calculate this:
DIS_1_1 = reshape(DIS(1,1,:),[1,360]);
DIS_1_1_Q90 = prctile(DIS_1_1,90);
DIS_1_1_belowQ90 = sum(DIS_1_1 < DIS_1_1_Q90) ./ 360 * 100;
Now I want to calculate this for every row and column. I hope someone can also give me some tips so that i can solve these kind of problems in the future.
Thanks in advance, Ruben

Best Answer

DIS_1_1_belowQ90 = sum(DIS < prctile(DIS,90,3),3)/size(DIS,3)*100; % R2016b and later
DIS_1_1_belowQ90 = ...
sum(bsxfun(@lt,DIS,prctile(DIS,90,3)),3)/size(DIS,3)*100; % R2016a and earlier