Problem with accumarray/histcounts

조회 수: 5 (최근 30일)
Emiliano Ascenzi
Emiliano Ascenzi 2020년 2월 11일
댓글: Emiliano Ascenzi 2020년 2월 11일
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