Calculating the directional and magnitude frequency of wind at spec... (2024)

8 views (last 30 days)

Show older comments

Jonathon Klepatzki on 7 Nov 2023

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles

Commented: Mathieu NOE on 15 Nov 2023

Accepted Answer: Mathieu NOE

  • windrose.pdf
  • WindRose.txt

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 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Mathieu NOE on 8 Nov 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#answer_1348627

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#answer_1348627

Edited: Mathieu NOE on 8 Nov 2023

Open in MATLAB Online

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 :

wind_rose(wind_direction,wind_speed) - File Exchange - MATLAB Central (mathworks.com)

and this is the result obtained in less than 1 minute of work

Calculating the directional and magnitude frequency of wind at spec... (3)

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

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 Comments

Show 6 older commentsHide 6 older comments

Jonathon Klepatzki on 8 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953687

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953687

Edited: Jonathon Klepatzki on 8 Nov 2023

Hey Matt,

I appreciate the help. I am 'relatively new' to coding despite taking one class during my undergrad. Therefore, I spend time writing and figuring out what works and doesn't work while developing something.

The attempt with frequency is to find how often specific wind directions occur (work demands). Any suggestions?

I also need to extract time from the file (datetime, I think would be good), any suggestions?

I am trying to do one thing. How can we extract data from a specific set of rows and plot it using wind rose? For example, use data from row 2751:2798). I tried it just now and got an error ("index must not exceed 18 or index in position 2 exceeds array bounds")

(Don't ask about the sum code, it was an experimental attempt).

I also appreciate the help with the code you provided as I found the wind rose function and couldn't quite get it to work.

Mathieu NOE on 8 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953752

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953752

hello again

ok, I understand you wanted to create your own code and not rely on someone else code (including the wind rose function)

now this is a work that is maybe a bit tough for someone just starting coding so I wonder what kind of result you need to provide

IMO what you have to do is to create a histogram , but here it would be nice to have it in polar coordinates and that's exactly what polarhistogram can provide

so I wonder why someone needs to reinvent this function or if you are allowed to use it

Mathieu NOE on 8 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953767

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953767

also I still don't have the answer about where does your meanfreq function comes from ? seems not in the standard matlab package (the only one I am aware comes from the Signal Processing Toolbox and has only one input argument : Mean frequency - MATLAB meanfreq - MathWorks France

Jonathon Klepatzki on 8 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953792

Edited: Jonathon Klepatzki on 8 Nov 2023

Yeah, it's a challenge for sure. I'm actually being forced to learn Python as I go (no excuse is allowed here at my particular position).

Before I found the wind rose code, is why I tried to develop my own. However, if I can find someone else's code that does what I need, I will gladly use it.

Ultimately, what I need is the number of times and count of (frequency) specific wind directions occurred (e.g., 330 degrees occurred x amount of times at time x on the 1st of January) at a given sector. Do that for the entire 24-hr period of January 1st. The follow-up will then do that for every single day and plot each one.

Jonathon Klepatzki on 13 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2959702

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2959702

@Mathieu NOE,

Can you verify my results from this code? I rewrote the main body to the following:

x = readmatrix('WindRose.txt')

WNDIR = x(2:2798,6);

WSPD = x(2:2798,7);

[C,ia] = unique(WNDIR)

W = WNDIR(ia,:)

[S,ia1] = unique(WSPD)

M = WSPD(ia1,:)

wind_rose(W,M)

I'm hoping that the unique function allows me to plot the windrose given the number of times a specific DIR and magnitude occurs beginning with the first row (row 2). On my end, the code works. I just would like a professional overview. Thanks!

Mathieu NOE on 14 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2960377

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2960377

Open in MATLAB Online

hello again

a few suggestions to improve your code (don't forget also the ; at the end of each line , otherwise you fill your command window with the content of each variable that appears in the line)

I wonder if applying unique is a good thing , why only plot unique events ? if the wind blows often at the same speed and / or direction, why hide this is the plot ?

x = readmatrix('WindRose.txt');

ind = (2:2798); % create once the rows indice and use it as many times as needed (reduce risk of bad manual input)

WNDIR = x(ind,6);

WSPD = x(ind,7);

[WNDIR,ia] = unique(WNDIR); % you have alreay the "new" WNDIR in the function output

WSPD = WSPD(ia,:); % don't forget to apply the ia selection to WSPD as well

[WSPD,ia] = unique(WSPD); % you have alreay the "new" WSPD in the function output

WNDIR = WNDIR(ia,:); % don't forget to apply the ia selection to WNDIR as well

wind_rose(WNDIR,WSPD);

Jonathon Klepatzki on 14 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2960952

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2960952

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 on 15 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2961722

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2961722

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

Sign in to comment.

More Answers (1)

Sakshi Sharma on 8 Nov 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#answer_1348622

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#answer_1348622

Open in MATLAB Online

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);

1 Comment

Show -1 older commentsHide -1 older comments

Jonathon Klepatzki on 8 Nov 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953692

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2044237-calculating-the-directional-and-magnitude-frequency-of-wind-at-specific-angles#comment_2953692

Hi Sakshi,

That's awesome, I appreciate the help. I gotta figure out how to frequencies now.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D Plots

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

  • compass
  • frequency
  • find

Products

  • MATLAB Coder

Release

R2023a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Calculating the directional and magnitude frequency of wind at spec... (14)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Calculating the directional and magnitude frequency of wind at spec... (2024)

FAQs

How do you calculate the direction of the wind? ›

The wind direction can be calculated using trigonometric functions: Angle = arctan(V/U), this is valid as long as U is not equal to zero. You must also adjust for what quadrant you are in based on whether U and V are positive or negative.

How to calculate wind frequency? ›

The number of times that a range ∆M of wind speeds occurred in the past is the frequency of occurrence. Dividing the frequency by the total number of wind measurements gives a relative frequency.

Is code 875 part 3? ›

This Code provides information on wind effects for buildings and structures, and their components. Structures such as chimneys, cooling towers, transmission line towers and bridges are outside the scope of this Code. There are Indian Standards dealing with chimneys and cooling towers separately.

What are the wind direction from UV components? ›

A positive u wind is from the west. A negative u wind is from the east. The v wind runs parallel to the y axis. A positive v wind is from the south, and a negative v wind is from the north.

How can you determine the direction of the wind answer? ›

A variety of instruments can be used to measure wind direction, such as the anemoscope, windsock, and wind vane. All these instruments work by moving to minimize air resistance. The way a weather vane is pointed by prevailing winds indicates the direction from which the wind is blowing.

What is the formula for wind? ›

Wind speed is calculated as follows: Instantaneous Wind Speed = Anemometer Factor x Instantaneous Shaft Speed. Average Wind Speed = Anemometer Factor x (Number of Turns / Time)

Is 875 a code for wind load? ›

IS-875 is the standard in India for design loads (other than earthquake) for buildings and structures. Basic wind speed as applicable to 10 m height above mean ground level for different zones in the country can be directly calculated if the proper value is defined in the Wind Zone Number box.

Is 875 1987 code? ›

IS 875 (part 1) - 1987: Indian Standard Codes provides design dead loads(Unit weights of building material and stored materials) for buildings and structures. IS 875 (part 3) - 1987: Indian Standard Codes provides design wind loads for buildings and structures.

Is 875 part 3 k2 factor? ›

K 2 factor is the height and terrain multiplier. As per IS 875, CL: 5.3. 2, for a given height of terrain, K 2 decreases, if the category of structure changes from Category 1 to Category 4.

What are the 3 factors that determine the direction the wind is blowing? ›

What are the three factors that affect the direction of wind flow...
  • Pressure gradient.
  • Rotation of the planet.
  • Friction.

How do you find prevailing wind direction? ›

The best way to determine the direction of prevailing winds at your home or business is to document the wind direction each day for a period of time. You can do this by setting up a weather vane or simply going outside and stand facing into the wind.

What is the formula for the wind component? ›

The crosswind component is equal to the speed (V) of the wind multiplied by the sine of the angular difference (XWC = V × Sineθ).

How can we measure wind direction? ›

Meteorologists study the strength and the direction of wind. One tool they use for measuring wind direction is a wind vane. It spins and points in the direction from which the wind is blowing. The wind can blow in every direction, but in many places most winds will blow in the same general direction.

How can we guess the direction of the wind? ›

Tie a lightweight string or tassel to an object and let it dangle. As the wind blows, the string or tassel will blow right along with it. The wind is blowing in the direction that the tassel points. Make an anemometer.

How do you determine prevailing wind direction? ›

The best way to determine the direction of prevailing winds at your home or business is to document the wind direction each day for a period of time. You can do this by setting up a weather vane or simply going outside and stand facing into the wind.

Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 5724

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.