index generation for multidimensional discretization

1 view (last 30 days)
Hi,
I require to discretize (bin) my feature space X, it has corresponding function values Y, therefore I need the index of the values in the bin.
So I have a very crude which does what I want but it is not that nice to expand for larger dimensions...
X = randn(1000,4,1);
Y = randn(1000,1);
nBins = 2;
[xD,E] = discretize(X,nBins);
idx = cell(nBins,nBins,nBins,nBins);
for i = 1:size(X,1)
idx{xD(i,1),xD(i,2),xD(i,3),xD(i,4)}(end+1) = i;
end
Y(idx{1,2,1,2},:)
Is there a pre-implemented code which does this (but in nice), or some fancy new algorithm which does bining with indexing (however I have only Matlab 2018 available)?
Kind Regards Max

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!