Calculating the directional and magnitude frequency of wind at specific angles

8 次查看(过去 30 天)
I am trying to calculate the frequency of the wind direction and speed at specific angles to be used in a compass plot. I am receving an error that states "incorrect inputs or outputs when using the find function. I have attached the PDF of the code and the datafile to be used. Any help would be greatly appreciated.

采纳的回答

Mathieu NOE
Mathieu NOE 2023-11-8
编辑:Mathieu NOE 2023-11-8
hello
well, your code looks a bit strange to me
first error is that find does not operate on table elements. You could have loaded directly your data as numeric data only with readmatrix (not need for readtable here)
then there are some lines wher the syntax makes me wonder where this code comes from :
% calculate specific direction based on frequency
N_freq = meanfreq(WNDIR,N_WND_IDX);
W_freq = meanfreq(WNDIR,W_WND_IDX);
S_freq = meanfreq(WNDIR,S_WND_IDX);
E_freq = meanfreq(WNDIR,E_WND_IDX);
I am not aware of a meanfreq function that has 2 input arguments (??)
also
U =
sum(W_freq(S_WSPD_freq,M_WSPD_freq,W_WSPD_freq,WW_WSPD_freq,C_WSPD_freq),E_freq...
(S_WSPD_freq,M_WSPD_freq,W_WSPD_freq,WW_WSPD_freq,C_WSPD_freq))
V =
sum(N_freq(S_WSPD_freq,M_WSPD_freq,W_WSPD_freq,WW_WSPD_freq,C_WSPD_freq),S_freq...
(S_WSPD_freq,M_WSPD_freq,W_WSPD_freq,WW_WSPD_freq,C_WSPD_freq))
wonder what this is supposed to do ... what are you trying to do ? what is the math behind this ?
at the end I wonder why you need to reinvent the wheel as they are already good stuff available on the FEX for wind rose plotting
let's pick this one :
and this is the result obtained in less than 1 minute of work
Tbl = readmatrix('WindRose.txt');
WNDIR = Tbl(:,6); % pulling wind direction data from column 6
WSPD = Tbl(:,7); % pulling wind speed data from column 7
wind_rose(WNDIR,WSPD); % see function below
%%%%%% FEX : https://fr.mathworks.com/matlabcentral/fileexchange/65174-wind_rose-wind_direction-wind_speed
function wind_rose(wind_direction,wind_speed)
%WIND_ROSE Plot a wind rose
% this plots a wind rose
figure
pax = polaraxes;
polarhistogram(deg2rad(wind_direction(wind_speed<25)),deg2rad(0:10:360),'displayname','20 - 25 m/s')
hold on
polarhistogram(deg2rad(wind_direction(wind_speed<20)),deg2rad(0:10:360),'FaceColor','red','displayname','15 - 20 m/s')
polarhistogram(deg2rad(wind_direction(wind_speed<15)),deg2rad(0:10:360),'FaceColor','yellow','displayname','10 - 15 m/s')
polarhistogram(deg2rad(wind_direction(wind_speed<10)),deg2rad(0:10:360),'FaceColor','green','displayname','5 - 10 m/s')
polarhistogram(deg2rad(wind_direction(wind_speed<5)),deg2rad(0:10:360),'FaceColor','blue','displayname','0 - 5 m/s')
pax.ThetaDir = 'clockwise';
pax.ThetaZeroLocation = 'top';
legend('Show')
title('Wind Rose')
end
  8 个评论
Jonathon Klepatzki
Jonathon Klepatzki 2023-11-14
Thank you for the tip! I was hoping that the unique function would do the following:
  • count the number of times a specific wind direction occurred (count) at a specific zone (e.g. 0 or 360 is zone 1)
  • calculate the frequency those winds occurred
  • plot the wind rose
  • disp or print the chart of the results
Mathieu NOE
Mathieu NOE 2023-11-15
well that's exactly the contrary, unique will remove all duplicates so in terms of statistics your are not taking into account the most frequent events and you will miss that in your plot
what you need to do is an histogram (see histcount) and that's what is doing the wind_rose function with polarhistogram

请先登录,再进行评论。

更多回答(1 个)

Sakshi Sharma
Sakshi Sharma 2023-11-8
find isn't going to work on a table, but it will work on the contents of a table. So in this case you can write:
W_WND_IDX = find(WNDIR.WDIR < 330 & WNDIR.WDIR > 210);

类别

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

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by