フィルターのクリア

Dividing a set of numbers into set of intervals and caculating the mean of each interval and comparing it with the previous one

10 ビュー (過去 30 日間)
Hi. I have a set of random numbers let's say x=[-2,-4,-7,-1,...,-3], and I need writting a code to divide x into equal intervals (let's say each interval has 50 numbers), then I want to caculate the mean of each interval and compare it with the mean of the previouse interval. Can any one help me with that please. your help is much appreciated in advanced.

採用された回答

Matt J
Matt J 2018 年 2 月 7 日
subs=discretize(x,50); %50 intervals
intervalMeans=accumarray(subs(:),x(:),[],@mean)
  13 件のコメント
Matt J
Matt J 2018 年 2 月 8 日
subs(i)=1 means x(i) belongs to interval #1 and subs(i)=2 means that x(i) belongs to interval #2.
Mohamed Saleh
Mohamed Saleh 2018 年 2 月 8 日
Thank you very much for your help.

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

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2018 年 2 月 8 日
編集済み: Jos (10584) 2018 年 2 月 8 日
I understood your question somewhat different: "I have N numbers {x(1) x(2) ... x(N-1) x(N)} and want to split them into several groups of K values: {x(1) ... x(K)} { x(K+1) ... x(2*K)} {...} without not changing the order of the elements. For each group I would like to take the mean."
There are several ways to answer this question. Examples:
% some data
X = randi(10,1,10) % N = 10
K = 3
% Note that N is not necessarily a multiple of K
idx = 1 + floor((0:numel(X)-1)/K)
M1 = accumarray(idx(:), X(:), [], @mean)
M2 = arrayfun(@(ix) mean(X(ix:min(ix+K-1,end))), 1:K:numel(X))

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by