Plot wind directions and speed of a day with quiver

13 views (last 30 days)
I have given two vectors holding 24 hourly values for wind speed and direction.
I would like to use quiver to plot 24 arrows indicating speed and direction graphically.
I failed with my first tries:
clc; % Clear the command window.
close all; % Close all figures
clear all; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
% given vector of windspeeds througout a day (every h)
windspeeds = rand(1,24)
% given vector of wind directions througout a day (every h)
% the direction is noted in degrees ° from nord
winddirections = randi([1 360],1,24)
% create x/y grid 24x24 for one day
[x,y] = meshgrid(1:24,1:24)
% substract 90° to re-align north to the top
u= mod(90 - winddirections, 360)
v= mod(90 - winddirections, 360)
% convert from degrees to fit the x/y matrix
u= cos(u) * pi/180
v= sin(u) * pi/180
% put it on quiver
quiver( cos(u) * pi/180, sin(u) * pi/180, x, y)
Current Result is
I do not yet know how to place these 24 arrows and how to calculate u,v to represent the direction at the given position (time of the day). The quiver doc is rather short. Any hints on how I could proceed.

Accepted Answer

KSSV
KSSV on 17 May 2017
workspace; % Make sure the workspace panel is showing.
% given vector of windspeeds througout a day (every h)
windspeeds = rand(1,24) ;
% given vector of wind directions througout a day (every h)
% the direction is noted in degrees ° from nord
winddirections = randi([1 360],1,24) ;
% create x/y grid 24x24 for one day
[x,y] = meshgrid(1:24,1:24) ;
% substract 90° to re-align north to the top
u= mod(90 - winddirections, 360) ;
v= mod(90 - winddirections, 360) ;
% convert from degrees to fit the x/y matrix
u= cos(u) * pi/180 ;
v= sin(u) * pi/180 ;
[U,V] = meshgrid(u,v) ;
% put it on quiver
quiver( x,y,U,V)
  2 Comments
MathMaus
MathMaus on 18 May 2017
Edited: MathMaus on 18 May 2017
Thanks. This helped me a lot to understand the way how quiver works. I now changed my approach and use a Rotation Matrix to rotate the initial vector into the right position. For that reason I have written a function which should take the components x,y, d,s %scaled initial vector pointing upwards as row-vectors. It would work fine for a single tuple of x,y,d,s but fails with row-vectors feet to the function.
function [vR]=drawWindDirection(x, y, d, s)
eV = [x, y + s]; % Draw Upright Einheitsvektor at given Position
% Construct the rotation Matrix
theta = d;
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
%
vR = eV * R;
%vR = eV .*R;
%vR =(R*eV.').';
end
I get the error: Error using * Inner matrix dimensions must agree.
vR = eV * R;
Of course the dimension of the arow vector and the rotation map are different. I'm sure this is another newby issue. How can I convince Matlab to calculate it, as i have learned it at School?
KSSV
KSSV on 18 May 2017
Mention the input x,y,d,s so that we can check the code.

Sign in to comment.

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!