Creating a polar histogram with x values (bins) that will appear on the graph even though no values fall into those bins?

6 views (last 30 days)
I am trying to make a polar histogram of values that actually are measured angles of axons exiting a brain structure (they are all measured in 2D). Essentially, these angles are all roughly between 1-270 degrees, but there are no measurements between 270 & 360. I have attached a histogram made of the data. My goal is to essentially "wrap" this histogram around a circle, but since there are no values for the last 1/4 of the x values, I'm not sure how to tell MATLAB that "there needs to be an empty section on this histogram at the end."
Thank you!

Accepted Answer

Steven Lord
Steven Lord on 31 May 2023
Do you need the histogram to be on a polar axes? If so use the polarhistogram function.
x = deg2rad(randi([0 270], 1, 1e6));
polarhistogram(x);
If not, just call histogram with a vector of bin edges and/or specifying the BinLimits name-value argument.
x = rand(1, 1e6);
h = histogram(x, 0:0.25:2);
h.BinEdges.'
ans = 9×1
0 0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000
Even though there's no data greater than 1, because I specified the bin edges that's what histogram used.
figure
h = histogram(x, 'NumBins', 16, 'BinLimits', [0 2]);
h.BinEdges.'
ans = 17×1
0 0.1250 0.2500 0.3750 0.5000 0.6250 0.7500 0.8750 1.0000 1.1250
16 equal width bins spanning from 0 to 2.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!