Binning data inside irregular 2d shape

2 views (last 30 days)
Elin Jacobs
Elin Jacobs on 21 Apr 2022
Commented: Elin Jacobs on 22 Apr 2022
I have three vectors of data, two representing x-y space (tempV and precV) and one representing z direction (acV). I also have an irregular shape and I want to bin all z data inside the shape (into more than one bin). I also have a logical vector for the datapoints that fall inside the shape. I want to plot the shape and the binned z data as bars. I have tried a number of options but am stuck because my bins in some cases fall outside the shape as the outline is not a rectangular. I'm guessing I need to change the x (P1) and y (A1) location of the z (ac1) data when I plot it, but havent figured out a good way to do so (like bin centers or similar). Below is what I have so far. In the attached figure, the five greenish bars that are closest to the x and y axes are in the wrong location, I want to force them to locations inside the same area as the other four (i.e., the are vaguely delineated by the black lines). Thanks.
load(data.mat)
%plot the outline of the shape
figure
plot(xv_1,yv_1) % polygon
%bin data and find bin edges
h1 = histogram2(tempV(in_1),precV(in_1),3);
p1bin = discretize(precV(in_1),h1.YBinEdges);
t1bin = discretize(tempV(in_1),h1.XBinEdges);
[P1,A1]=ndgrid(h1.XBinEdges(1:end-1),h1.YBinEdges(1:end-1));
ac1 = accumarray([t1bin,p1bin],acV(in_1),[],@sum);
cm1 = [0.650 0.612 0.192];
figure
scatterbar3(P1,A1,ac1,1) %function from file exchange
colormap(cm1)
  2 Comments

Sign in to comment.

Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by