You can set figure's ButtonDownFcn
property to a function that will get the CurrentPoint
with X coordinates.
set(gcf,'ButtonDownFcn',@your_bd_function)
(You can use any figure handle instead of gcf
, of course.)
Then in the function
curpnt = get(gca,'CurrentPoint'); % returns [x y] vector where you clicked
(Again use appropriate axis handle here.)
If you have one value per bin and it's integer, then the rest is easy:
out = atable(data==round(curpnt(1)),:);
For more complex case you need to find the boundaries for the bins and select the data accordingly. It would be easier if you return the data from hist as [y,x] = hist(data,bin);