How do I use histcounts with overlapping bins?
8 ビュー (過去 30 日間)
古いコメントを表示
First off, there's only this post I found with some relevant inputs, although the comments suggested overlapping bins may not work with histcounts?
My question is this: Is there a way to create bin egdes by giving the number of bins (which histcounts does) and the percentage overlap between bins to generate a set of overlapping bins which can be used with accumarray later on?
More specifically, I have vectors x, y and z covering a spatial volume. I need to "discretize" this volume and bin the vector V.. (which is when I found the answer on 3D binning). I am looking for a way to extend this by adding overlapping bins.
Is there a way to achieve this? Any help is appreciated. Thanks!
4 件のコメント
Steven Lord
2019 年 3 月 29 日
Do you need to visualize the overlapping bins (histogram) or just compute with overlapping bins (histcounts)?
採用された回答
Walter Roberson
2019 年 3 月 28 日
Discretize three times per dimension, once with the bins exactly where you want them, once with the bins [overlap] earlier, once with the bins [overlap] later. Do the 27 different 3D binnings (each possible combination of early, middle, late), taking lists of indices. Then take the union of all of the indices in corresponding bins.
6 件のコメント
その他の回答 (1 件)
Matt J
2019 年 3 月 28 日
編集済み: Matt J
2019 年 3 月 28 日
If you're willing to make some approximations in the interest of speed, this is a method that will do the whole 3D accumarray operation. It uses some FEX contributions that you must download, namely KronProd and ndSparse. Basically, it first histograms the x,y,z data normally into super-thin, non-overlapping bins. Then it basically consolidates those into overlapping bins by separable convolution.
%% simulated data
vmin=0; vmax=10; %integer min and max assumed here
x=rand(1,10000)*(vmax-vmin)+vmin;
y=rand(1,10000)*(vmax-vmin)+vmin;
z=rand(1,10000)*(vmax-vmin)+vmin;
%% binning parameter selections
binShift=0.5; binWidth=1;
%% Set-up computations
lowerEdges=vmin:binShift:vmax-binWidth;
upperEdges=lowerEdges+binWidth;
Nbins=numel(lowerEdges);
delta=vmax-vmin;
N=1000*delta;
L=(lowerEdges.')*N/delta+1;
U=(upperEdges.')*N/delta+1;
T=cumsum(sparse(1:Nbins,L,1,Nbins,N+1)-sparse(1:Nbins,U,1,Nbins,N+1),2);
C=KronProd({T(:,1:N)},[1,1,1]); %separable convolution operator
%% Do computation
tic;
e=linspace(vmin,vmax,N);
I=discretize(x,e).';
J=discretize(y,e).';
K=discretize(z,e).';
H=ndSparse.build([I,J,K],1,[N,N,N]);
A=full(C*H); %The "accumarray" result
toc; %Elapsed time is 1.182683 seconds.
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!