フィルターのクリア

Problem with accumarray/histcounts

1 回表示 (過去 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.
  1 件のコメント
Emiliano Ascenzi
Emiliano Ascenzi 2020 年 2 月 11 日
It's perfect, thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by