I think it is actually putting the data in bins correctly, but just the display is wrong. It has to do with the scaling of the bins: each bin is not the same size and therefore needs a factor that comes from the size of the polar grid, but I'm not sure how to do that.
How do I create a Polar Bivariate Histogram?
12 次查看(过去 30 天)
显示 更早的评论
I am trying to create a histogram in polar coordinates, but I can't use the rose command because I want the histogram to depend both on rho and theta. It was easy to create this in Cartesian coordinates because I could just use hist3 (in the Statistics Toolbox), which doesn't exist for polar.
The input coordinates are in histData which is an Nx2 matrix with the x,y coordinates of each point. I based my code off of Doug's Histogram, but have been having issues of converting it to polar.
As you can see from the pictures below (Cartesian one is correct), it has somehow flipped the distribution from center-heavy to edge-heavy. Also there's always once slice that has a substantially lower density than the others, which shouldn't happen.
[histPolth,histPolr] = cart2pol(histData(:,1),histData(:,2));
rBins = 3;
thBins = 5;
width = 5; % size of circle
thi = linspace(-pi,pi,thBins);
ri = linspace(0,width/2,rBins);
[TH,R] = meshgrid(thi,ri);
[X,Y] = pol2cart(TH,R);
thHist = interp1(thi,1:length(thi),histPolth,'nearest');
rHist = interp1(ri,1:length(ri),histPolr,'nearest');
Z = accumarray([thHist rHist],1,[thBins rBins])';
figure()
surf(X,Y,Z);
view(2); % flatten to 2-D
daspect([1 1 1]); % set aspect ratio
MATLAB 2011a (Mac)
采纳的回答
Michael
2014-8-5
3 个评论
Anne-Laurène Panadero
2016-3-4
Hi Michael and Mitchell,
I have to admit that I am in the position Mitchell was a few weeks ago and I have issues to understand what you did to make it work on the 7th of July 2014. May I ask you as well if you could to post your amended script ?
Thank you,
Anne-Laurene
更多回答(1 个)
Frederick Zittrell
2019-4-1
I wrote this function that creates a bivariate histogram from polar coordinates:
The histogram grid is a simple cartesian grid and not a radial grid, though.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!