MATLAB: Problem with accumarray/histcounts

accumarrayMATLAB

I have a table with 2 columns (attached), I'm looking to evaluate and plot mean value of X every 10 records in function of mean value of Y every 10 records. The output i'm looking for is a plot where i have 208/10 = 20/21 points, every point is the mean value of 10 X and Y values.
I tried this code but i receive error
[N,edges] = histcounts(C,21);
V = accumarray(edges,C,[],@mean)

Best Answer

This isn't the easiest to understand algorithm in the world but I think it does exactly what you want.
n = size(C,1)
ix = ceil(mod((1:n)/10, ceil(n/10)))';
accumarray([[ix;ix], [ones(n,1);ones(n,1)+1]],C(:),[],@mean)
ix is ten 1s, then ten 2s, etc. up until 8 21s.
This is replicated twice in accumarray for each column of C. The second column of subs is 208 1s followed by 208 2s indicating first and second column. vals is all valuex of C.