3

I am producing many angle histogram plots using rose2.m. I would like the scale showing the number of elements in each bin to range between 0-50, increasing by increments of 10, for all plots, even if the max number of elements on a particular plot is less than 50. Does anyone know how I can do this please? Thanks.

1

3 Answers 3

1

This question is the same as this one but you are looking at a special case of rose2.

I was able to lock the max value to 50 with the following code. First I plot an empty point at 50 then hold on to lock the plot. rose2 then uses those bounds.

The code:

x = (rand(100,1)*pi);

maxHistogramValue = 50;

figure(44);
clf
% Set the max value to maxHistogramValue:
polar(0, maxHistogramValue,'-k')
hold on;

% Now use rose2:
rose2(x);
1

Here is another example (based on @Steve's idea):

%# data and angular histogram
x = rand(400,1) .* 2*pi;
[t,r] = rose(x);                %# this does not generate a plot

%# set plot's max radial ticks
figure
rMax = 50;
h = polar(0, rMax);
delete(h)
set(gca, 'Nextplot','add')

%# draw patches instead of lines: polar(t,r)
[x,y] = pol2cart(t,r);
h = patch(reshape(x,4,[]), reshape(y,4,[]), 'b');
alpha(h, 0.5)       %# note: this switches to OpenGL renderer

screenshot

This way you get to control the maximum radius, though you can't really control the number of steps (POLAR function always prefers around 5 radial ticks; see the source code).

0

I'm not entirely clear on what rose2.m is, but I'd imagine that you can set your own scale/legend if you have the necessary data to do so.

It sounds like you have an array/vector of angle that range between 0 and 50. We'll call that angleArray for now.

To get the number of elements that fall into each bin (0-50 in 10 unit incriments) you can use the following line of code:

binCounts = histc(angleArray, 0:10:50);

binCounts will be a 1 by n, where n is length(0:10:50) and have the counts of the number of values for each bin. That data can then be used to populate your scale.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.