# How do I plot wind direction timeseries with arrows

44 views (last 30 days)
giacomo labbri on 12 Jun 2020
Commented: Fego Etese on 15 Jun 2020
Hi,
I would like to plot a timeseries of wind direction. I would like represent the direction at each point in time with an arrow. The direction of the wind is expressed in degrees. I have saw that quivers might do what I want with some tricks but I was wondering if there was a more specific function.
Giacomo

giacomo labbri on 12 Jun 2020
addition: my data are stored in a timetable where the time is datetime data type so if there is a function that takes datetime data as input it would be great
Adam Danz on 12 Jun 2020
As my answer indicates, the quiver function is what you should use given the description of the problem. However, the quiver function does not accept datetime values. It only accepts numeric values or values that can be converted to double. That's for a good reason. Imagine a vector whose base is at x="January 1, 2000" and y = 10 and has (u,v) components of (2,1) (in other words, it extends 2 units in the x direction and 1 unit in the y direction). What does that mean with datetime values?
What is "2" in datetime? 2 days? 2 hours? Matlab wouldn't be able to figure that out. But you could figure that out since you know the context of your data.
So, you'll need to convert the datetime values in order to use quiver. Then you can set the x tick labels aftewards to datetime values using datetick.
giacomo labbri on 13 Jun 2020
thanks that was really helpful! :)

Adam Danz on 12 Jun 2020
The quiver() function is what you want to use. It's desiged exactly for this purpose.
Since your vectors are in degrees and the quiver function requires the x,y component vectors, use pol2cart() to convert your polar vectors to cartesian vectors. You'll also need to convert deg-->rad for the pol2cart inputs.
% WindDirection is the direction of wind (deg)
% WindSpeed is the magnitude of the wind vector
[xWind, yWind] = pol2cart((pi/180).*WindDirection), WindSpeed);
quiver(x, y, xWind, yWind)

#### 1 Comment

Fego Etese on 15 Jun 2020
I'll really appreciate your help, thanks