MATLAB: How to extract a distribution from a 2d histogram

histogrammarginal distributionsMATLAB

How can I extract a distribution from a 2d histogram?
Good morning,
I have created a 2D histogram. That is straight forward, I have the 3 matrix, X Y the grid and Z, the number of counts in each cell of the grid.
Now it comes my question, the big histogram, (that you can see in the attached photo) gives me a lot of information but I need the marginal histogram, for example I want to know the number of counts (Z) but only along the line y=-2x+1.
Can you give me a bit of help?
Thank you very much in advance

Best Answer

Look HERE and HERE