How do I use histcounts with overlapping bins?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Prodip Das
il 27 Mar 2019
Commentato: Steven Lord
il 29 Mar 2019
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 Commenti
Steven Lord
il 29 Mar 2019
Do you need to visualize the overlapping bins (histogram) or just compute with overlapping bins (histcounts)?
Risposta accettata
Walter Roberson
il 28 Mar 2019
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 Commenti
Più risposte (1)
Matt J
il 28 Mar 2019
Modificato: Matt J
il 28 Mar 2019
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.
Vedere anche
Categorie
Scopri di più su Data Distribution Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!