I would like to subset an array of serial numbers representing dates, according to recession periods, so that I can calculate `mean()` over these periods. The following example illustrate this:

```
DateArray = transpose((1:20000)+678420);
RndData = normrnd(0.003,0.05,19999,1);
CumData = cumprod([1;RndData+1]);

Data = [DateArray CumData];

load Data_Recessions.mat %Native `Econometrics toolbox` dataset
% This loads a 2 column double array of start dates in the first column and corresponding end dates in the second column.

plot(Data(:,1),Data(:,2))
set(gca(),'Yscale','log');
recessionplot()

```

![enter image description here](https://i.stack.imgur.com/SsMkU.jpg)

I thus want to calculate mean() over the grey bars above. The dates indicating these periods are in the Recessions array. How do I do this most efficiently?