matlabstatisticshistogramnormalizationrose-plot

How to plot probability density with rose plot in matlab


I am trying to plot normalized, probability histogram with rose function in matlab (I can't use polarhistogram because I do not have the latest version of Matlab. My version is 2015b).

In a normal histogram, I usually do it like this:

h = histogram(x,'Normalization','probability');

But the same doesn't work for rose. If I try passing h.Values to rose plot, this doesn't work, because the rose uses this as the data, not as values...

x=rand(100)*90;
xRad = x(:)./180*pi;
xRadProb = histogram(xRad,'Normalization','probability');
figure(1)
hax = axes();
rose(hax, xRadProb.Values,10)

Any suggestions how to do this? Thanks a lot!


Solution

  • It seems you need to do the normalization yourself. But it's easy. For 'probability', the normalization simply consists in dividing the un-normalized result (count for each bin) by the total number of data values.

    So, use the two-ouput version or rose, normalize, and then use polar (in R2015b) or polarplot (in more recent Matlab versions) to do the polar plot:

    [t, r] = rose(xRad, 100); % 100 is desired number of bins. Set as needed
    r = r./numel(xRad); % normalize
    polar(t, r) % polar plot
    

    enter image description here

    As a check, following is the result of polarhistogram with the same number of bins. Note that in this function the bins are adjusted to the actual data range, so 25 needs to be specified instead of 100 in the example:

    polarhistogram(xRad, 25, 'Normalization', 'probability')
    

    enter image description here