MATLAB: Q90 percentile for monthly time series

arrays

Hi, I want to calculate the 90 percentile for every seperate month from the following data a = 27,23,360. And then use this to evaluate for a second dataset b = 27,23,360 the occurrence of points below this treshold and calculate the percentage.
I started:
s = size(a);
a1 = reshape(a, s(1), s(2), 12 , s(3) / 12);
a2 = prctile(a1,90,4);
(bsxfun(@lt,b,a2);
Now i get the following error: Non-singleton dimensions of the two input arrays must match each other.
This is propably because a2(27,23,12) does not match b(27,23,360). However, im not sure how to code that differently.
Thanks

Best Answer

s = size(a);
a1 = reshape(a, s(1), s(2), 12 , s(3) / 12);
a2 = prctile(a1,90,4);
b1 = reshape(b, s(1), s(2), 12 , s(3) / 12);
out = sum(bsxfun(@lt,b1,a2),4)*12/s(3)*100;