フィルターのクリア

Binning elements between limits

2 ビュー (過去 30 日間)
NS
NS 2012 年 8 月 6 日
Hi all,
I have a m*2 matrix. Column 1 is the X position while Column 2 is the distance. Column 2 has a range from 0-20. I want to bin the values of column 1. Bin 1 should include all the values of X that have a corresponding distance between 0.9-1.1, Bin 2 should have all values of X having distance between 1.9-2.1 and so on. I want to have about 10 bins. I want to calculate the variance of the position elements in each bin. Is there a function to do this is MATLAB?

回答 (3 件)

Oleg Komarov
Oleg Komarov 2012 年 8 月 6 日
編集済み: Oleg Komarov 2012 年 8 月 6 日
Yes the function is called histc(). Read the documentation carefully.
Example:
[n,bin] = histc(A(:,2), [0.9,1.1,1.9,2.1])
Then to calculate the var():
accumarray(bin, A(:,2),[],@var)
  1 件のコメント
NS
NS 2012 年 8 月 7 日
Thanks Oleg. I will have a look at it.

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


John Petersen
John Petersen 2012 年 8 月 6 日
編集済み: John Petersen 2012 年 8 月 6 日
histc gives you the number of elements in the bins. Below code should give variance of the elements in the bins:
% X is position
% D is distance
binwidth = 0.1;
n = 10; % number of bins
vx = zeros(n,1);
for k=1:n
ind = (D>k-binwidth)&(D<k+bindwith); % index of bins
vx(k) = var(X(ind)); % variance of X bins
end
  1 件のコメント
NS
NS 2012 年 8 月 7 日
Thanks John. I will have a look at it.

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


Matt Fig
Matt Fig 2012 年 8 月 6 日
Here I show an example of what I think you are getting at, though it is still a little unclear to me.
D = rand(30,2)*20; % Example data.
BINS = bsxfun(@plus,[.9 1.1].',0:18); % Example; make your own...
[I,I] = histc(D(:,2).',[-inf BINS(:).' inf]); % Pass column 2
A = accumarray(I.',D(:,1), [], @(x) {x});
A = A(2:2:end); % Here are col 1 matches to bins of col 2.
V = cellfun(@var,A); % And the variances of each
  1 件のコメント
NS
NS 2012 年 8 月 7 日
Thanks Matt. I will have a look at it.

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

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by