Add arrows to surface plot to represent wind direction

Hi there,
I am seeing a lot of information about the quiverm function but I only have my wind direction data in degrees and not in the u and v components. Is there a simple way to project a matrix of wind direction values (360 degrees) onto a sufacem plot? Perhaps there is a way to add and arrow and align it based on the wind direction value? I do not want to add magnitude as well, just direction.
Many thanks,

7 件のコメント

Kirby Fears
Kirby Fears 2015 年 9 月 23 日
編集済み: Kirby Fears 2015 年 9 月 23 日
The built-in functions "cosd" and "sind" apply cosine and sine to an angle specified in degrees.
u=cosd(deg);
v=sind(deg);
These will give you the unitary direction of wind. Check out the documentation for quiver. An excerpt is below.
A quiver plot displays velocity vectors as arrows with components (u,v) at the points (x,y).
For example, the first vector is defined by components u(1),v(1) and is displayed at the point x(1),y(1).
quiver(x,y,u,v) plots vectors as arrows at the coordinates specified in each corresponding pair of elements in x and y. The matrices x, y, u, and v must all be the same size and contain corresponding position and velocity components.
mashtine
mashtine 2015 年 9 月 23 日
Hi Kirby, thanks for this! I tried using this as well but the u and v that I got did not go back into returning the same wind direction. Perhaps I did something wrong when reconverting.
>> r2d = 45.0/atan(1.0);
>> atan2(cosd(100), sind(100)) * r2d + 180
ans =
170
Kirby Fears
Kirby Fears 2015 年 9 月 23 日
I don't see what you're trying to do in these two lines of sample code. What angle are you trying to convert to unit vector representation?
The angle you plugged into cosd and sind is 100 degrees. You can easily convert back and forth.
u=cosd(100);
v=sind(100);
originalAngle=atan2d(v,u)
originalAngle =
100
mashtine
mashtine 2015 年 9 月 23 日
編集済み: mashtine 2015 年 9 月 23 日
Hi Kirby,
Thanks again. I was basing my equation off of this site https://www.ncl.ucar.edu/Document/Functions/Built-in/atan2.shtml
I was simply trying to work backwards using cosd and sind
Kirby Fears
Kirby Fears 2015 年 9 月 23 日
編集済み: Kirby Fears 2015 年 9 月 23 日
The "x" component is typically denoted as u and the "y" component as v. In the link you posted, it's the other way around. Moreover, there's no reason to add 180 at the end. The NCL website seems to be counting degrees in some nonstandard way. In trigonometry you start counting from 0 degrees (in the (1,0) direction) and proceed counter-clockwise around the unit circle. To fix your earlier calculation:
>> r2d = 45.0/atan(1.0);
>> atan2(sind(100),cosd(100))*r2d
ans =
100
When it comes to using Matlab functions, I think you'll find the Mathworks documentation more helpful than the NCL website.
If this answers your question, please remember to "Accept" my answer so the issue is closed.
mashtine
mashtine 2015 年 9 月 23 日
Hi Kirby,
I believe the NCL website is giving the correct data as it will produce the correct wind direction for the negative quadrants. I am also getting the expect wind direction (easterly winds). For instance,
atan2(sind(181),cosd(181))*r2d
ans =
-179
where I should not be getting a negative direction but degrees in 0 to 360. I believe it is accounting for matlab use of the atan2 function as this differs in some software
Kirby Fears
Kirby Fears 2015 年 9 月 23 日
-179 is the correct answer.
-179+360=181
The NCL website adds 180 to this, which would be
-179+180=1, which is incorrect.

サインインしてコメントする。

 採用された回答

Kirby Fears
Kirby Fears 2015 年 9 月 23 日
編集済み: Kirby Fears 2015 年 9 月 23 日

0 投票

I'm posting an example as described in my earlier comment.
Code below creates a 10x10 grid of arrows that are all pointing at 120 degrees.
x=repmat(1:10,10,1);
y=x';
deg=120; % all points have same direction
% if you have a degree array the same size as x,
% you can use cosd and sind on "deg" without
% using repmat after
u=repmat(cosd(deg),size(x));
v=repmat(sind(deg),size(x));
% you can multiply u and v by magnitude of required
quiver(x,y,u,v);

5 件のコメント

mashtine
mashtine 2015 年 9 月 23 日
編集済み: mashtine 2015 年 9 月 23 日
This code seems to work and is certainly a good start! but the average direction that my wind is coming from is 85 degrees, thus an easterly wind, yet the quiver produces arrows that point north north east and would come from a south south westerly direction. Not really sure why this is.
Kirby Fears
Kirby Fears 2015 年 9 月 23 日
編集済み: Kirby Fears 2015 年 9 月 23 日
85 degrees in trigonometric terms points "north-north-east" in the unit circle. If you're going to use trigonometric functions (e.g. sin, cos, tan), you need to be thinking in terms of mathematical degrees only.
There appear to be important differences in what degrees means in mathematics and what it means in your mapping assignment. You will need to understand both meanings of degrees and convert between them as needed. Don't try to input your map-degrees into trig functions or expect that as output from inverse trig functions like atan.
mashtine
mashtine 2015 年 9 月 24 日
Yes that makes sense and I gather the difference between the unit circle and the convention used in meteorological terms. Sorry if my explanation was off but I thought you understood this was my intended output. So given that I have map degrees, is there a way to get u and v components that will get that meteorological map degree? I believe this to be my last question!
Thank you for bearing with me Kirby,
Thorsten
Thorsten 2015 年 9 月 24 日
Use
cosd(90 - deg)
sind(90 - deg)
mashtine
mashtine 2015 年 9 月 24 日
Thanks a lot Thorsten! As the I would like the arrows to point to where the wind is going to, I will use
cosd(270 - deg)
sind(270 - deg)
That seems to be working well for all degrees.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVector Fields についてさらに検索

質問済み:

2015 年 9 月 23 日

コメント済み:

2015 年 9 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by