Indices after accumarray in order to do N-dimensional histograms
Show older comments
Hello everyone,
I am using an accumarray function in my script in order to computer N-dimensional histograms. This is the line:
ht = accumarray(sub, 1, nBins+1 .* ones(1, nFeat));
where nBins stands for the number of Bins in my histogram and nFeat the number of features (so the dimension of my histogram).
If I use for example this set of data:
[1 2 ; 2 3 ; 1 2 ; 1 3 ; 1 1 ; 3 2]
My 2-dimensional histogram will be:
H = [1 2 1;
0 0 1;
0 1 0]
The first value for example says that there is 1 occurrence of 1 1, the second value 2 occurrences of 1 2...
However I want to keep the indices. In this example, I would like to have something like that:
Hind = {5}, {[1 3]}, {4};
{ }, { }, {2};
{ }, { 6 }, { }
I don't really care about it being in cells or something else.
The number is the cell are just the linear indices of the values that contributed to the histogram.
Basically, I want the indices that could allow me to generate my histogram for example by doing:
H = cell2mat(cellfun(@numel, Hind, 'Un', false));
I hope this was clear.
Thanks a lot,
Quentin
4 Comments
Steven Lord
on 6 Jun 2019
How large is N and how many bins do you want in each dimension? If either of those numbers are large (or if both of them are medium sized) that could require a lot of memory.
Quentin Garçon
on 6 Jun 2019
Edited: Quentin Garçon
on 6 Jun 2019
Steven Lord
on 9 Jun 2019
So nFeat could be up to 10. What is an upper bound on nBins? If it's too large, even storing "only the indices" could require more memory than is available on the planet or in the known universe.
Quentin Garçon
on 10 Jun 2019
Accepted Answer
More Answers (1)
Quentin Garçon
on 8 Jun 2019
0 votes
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!