Calculating the directional and magnitude frequency of wind at specific angles
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jonathon Klepatzki
le 7 Nov 2023
Commenté : Mathieu NOE
le 15 Nov 2023
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.
0 commentaires
Réponse acceptée
Mathieu NOE
le 8 Nov 2023
Modifié(e) : Mathieu NOE
le 8 Nov 2023
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 commentaires
Mathieu NOE
le 15 Nov 2023
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
Plus de réponses (1)
Sakshi Sharma
le 8 Nov 2023
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);
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!