What is wrong with my approach to building this histogram?

1 回表示 (過去 30 日間)
Jegor
Jegor 2024 年 11 月 18 日
回答済み: Steven Lord 2024 年 11 月 18 日
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 日
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 Center および File ExchangeHistograms についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by