Calculating the directional and magnitude frequency of wind at specific angles
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Jonathon Klepatzki
il 7 Nov 2023
Commentato: Mathieu NOE
il 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 Commenti
Risposta accettata
Mathieu NOE
il 8 Nov 2023
Modificato: Mathieu NOE
il 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 Commenti
Mathieu NOE
il 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
Più risposte (1)
Sakshi Sharma
il 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);
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!