Problem with accumarray/histcounts

1 次查看(过去 30 天)
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)

采纳的回答

Sean de Wolski
Sean de Wolski 2020-2-11
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by