Filter löschen
Filter löschen

Problem with accumarray/histcounts

1 Ansicht (letzte 30 Tage)
Emiliano Ascenzi
Emiliano Ascenzi am 11 Feb. 2020
Kommentiert: Emiliano Ascenzi am 11 Feb. 2020
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)

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by