How to exclude bins from a bi-variate histogram

7 views (last 30 days)
Hi, I have been some of the bins from the a bi-variate histogram of the following density plot/histogram. I don't want to have my histogram horizontally between x>=-0.002 & x<0.002 and vertically between y>=-0.002 & y<0.002.
I have tried the following code
xL = xpos>=-0.002 & xpos<0.002; % xpos is the position in x-axis
x = xpos(~xL,:);
yL = ypos>=-0.002 & xpos<0.002; % ypos is the position in y-axis
y = ypos(~yL,:);
h = histogram2(x,y,[100,100],'DisplayStyle','tile','ShowEmptyBins','on');
But it is giving error as my length of x and y are different. I will appreciate if anyone let me know how to make my histogram2 plot excluding those region. Thanks in advance.

Answers (2)

Steven Lord
Steven Lord on 3 Aug 2018
Don't eliminate data points from your xpos and ypos arrays. Instead, specify XBinLimits and YBinLimits when you call histogram2.
  1 Comment
Ashfiq
Ashfiq on 5 Aug 2018
Hi, Thanks. Actually I want to eliminate that region in the middle.Do you know is there any way that I can have that histogram below -0.002 and above 0.002 in both x-axis and y-axis using XBinLimits and YBinLimits ? Because in this case I will have two min and max values. Thanks in advance.

Sign in to comment.


Image Analyst
Image Analyst on 3 Aug 2018
You say you have an image of "bins from the a bi-variate histogram of the following density plot/histogram." So the data in the image already represents counts (a histogram). Why why then are you calling histogram2()? Why are you calling histogram on a histogram? And what is xpos and ypos exactly? Is that like what you'd get from meshgrid, basically a 2-D array of the x and y coordinates? If so, then what variable is displayed in the image?
Do you just want to crop the displayed/existing histogram to be a smaller image (smaller range)?
  1 Comment
Ashfiq
Ashfiq on 5 Aug 2018
Edited: Ashfiq on 5 Aug 2018
Hi, Thanks for your concern. Actually this is not a histogram plot for an image whereas horizontally it is the position of an element in x-axis which is defined as 'xpos', and 'ypos' is defined as the y-axis positions which you can see on the vertical axis. What I basically wanted to see is the density plot of the element how much it is concentrated through the space and whether it is uniformed or not. But, it seems like I have some noise in the middle. Therefore, I wanted to get rid of those noise and make same spatial density plot. I hope this clarifies what you asked.

Sign in to comment.

Categories

Find more on Data Distribution Plots 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!