What is wrong with my approach to building this histogram?

16 次查看(过去 30 天)
I am working on a project that builds a histogram based on the data selected by the user in the program. I am facing an issue with how my histogram is built. I use the code below to build it. 'Theta' there is one of the possible data arrays that can be selected. The histogram on the left is built using my approach. However, it should look like the one on the right. What am I doing wrong and how can I revise my approach to building it? Edit: I have to add that 'Theta' contains the azimuth changes of the wind direction measured at a weather station. So I suppose this might play a part why my histogram is not correct.
theta=[236 239 154 237 267 107 102 103 95 104 101 110 94 99 97 97 118 123 115 123 94 96 119 101]
p = polarhistogram(theta,16);
ax = gca;
ax.ThetaLim = [0 360];
ax.ThetaTickLabel = {'E','NE', 'N', 'NW', 'W', 'SW', 'S', 'SE'};
ax.ThetaTick = (0:45:360);

回答(1 个)

Steven Lord
Steven Lord 2024-11-18,15:47
From the documentation for the polarhistogram function: "polarhistogram(theta) creates a histogram plot in polar coordinates by sorting the values in theta into equally spaced bins. Specify the values in radians." [Emphasis added.]
Your theta values look like angles in degrees. Use deg2rad to convert your data to radians.
theta=[236 239 154 237 267 107 102 103 95 104 101 110 94 99 97 97 118 123 115 123 94 96 119 101];
p = polarhistogram(deg2rad(theta),16);

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by