I want to program a function in C++ which does the same thing as the function histcounts
in Matlab, but I don't get the right edges.
[V, edges]=histcounts(Vector,10);
I found this post : implementing matlab hist() in c++ and I created a function which I thought should work. How do I get the same edges in my function as in histcounts
?
My Code :
int n =10;
double histogrammdistance = (ceil(*max_element(std::begin(Vector), std::end(Vector)))-floor(*min_element(std::begin(Vector), std::end(Vector))))/n;
vector<double> edges;
double minY = *min_element(std::begin(Vector), std::end(Vector));
for (int i = 0 ;i <=n; i++)
{
edges.push_back(floor(minY) + histogrammdistance * i);
}
So My Problem right now is :
i have this Vector = [-37,0329218106996 -26,9722222222222 -34,0823045267490 -33,0987654320988 -39 -35,0658436213992 -30,8061224489796 -36,0493827160494 -38,0164609053498 -12]
Matlab creates these edges :
edges [-40 -37,2000000000000 -34,4000000000000 -31,6000000000000 -28,8000000000000 -26 -23,2000000000000 -20,4000000000000 -17,6000000000000 -14,8000000000000 -12,0000000000000]
But my Program doesn't use -40 to calculate the binwidth..because the minimum number is -39 and not -40. Also if i change -39 to -38.5... matlab is still picking -40
1, Question : Why is Matlab taking -40 ... and has sb an idea how this could be implemented ?
i created now a very simpel Vector with [1 2 3 4 5] if i take 15 as bin number i get this as solution [1 1.27 1.54 1.81 ...] bit if i take 13 as bin number it doesn*t start with the min number 1 :/ it starts with [0,90 1,2 1,54 1,8 2,18....]
2. Question : do sb know why it took 0.90 ??