Plot of windspeed and wind direction in time series

Is it possible in Matlab to plot windspeed and wind direction in a time series for historical analysis of wind direction. I have wind direction (degN) and wind speed (m) and would like to have a plot similar to attached picture (from weatherunderground.com)
Here is some sample data
Date [736615.333333333
736615.334027778
736615.334722222
736615.335416667
736615.336111111
736615.336805556
736615.337500000
736615.338194444
736615.338888889
736615.339583333]
Wind direction [170.100000000000
171.500000000000
176.300000000000
173.300000000000
174.600000000000
173.900000000000
173.900000000000
169.500000000000
168.800000000000
171.500000000000]
Wind Speed [2.85200000000000
2.30800000000000
2.33200000000000
2.18000000000000
2.61000000000000
2.43000000000000
2.90700000000000
2.57900000000000
2.38800000000000
2.80900000000000]
Thanks for any assistance

1 commentaire

Tim
Tim le 27 Mar 2018
Did you manage to get a script to plot your data like the output from Weatherunderground? Struggling with Quiver too

Connectez-vous pour commenter.

Réponses (3)

filecontent = fileread('YourFileNameHere.txt');
open_pos = find(filecontent == '[');
close_pos = find(filecontent == ']');
direction_substring = filecontent(open_pos(1)+1 : close_pos(1)-1);
speed_substring = filecontent(open_pos(2)+1 : close_pos(2)-1);
direction_split = regexp(direction_substring, '\s+', 'split');
speed_split = regexp(speed_substring, '\s+', 'split');
direction = str2double(direction_split);
speed = str2double(speed_split);
quiver(speed, direction*pi/180);

8 commentaires

This works for a scatter plot on speed and direction. How do I add a time component? The sample data is updated accordingly. Thanks.
filecontent = fileread('YourFileNameHere.txt');
open_pos = find(filecontent == '[');
close_pos = find(filecontent == ']');
date_substring = filecontent(open_pos(1)+1 : close_pos(1)-1);
direction_substring = filecontent(open_pos(2)+1 : close_pos(2)-1);
speed_substring = filecontent(open_pos(3)+1 : close_pos(3)-1);
date_split = regexp(date_substring, '\s+', 'split');
direction_split = regexp(direction_substring, '\s+', 'split');
speed_split = regexp(speed_substring, '\s+', 'split');
dates = str2double(date_split);
direction = str2double(direction_split);
speed = str2double(speed_split);
However at this point I am not sure what a good plotting routine would be. Generally speaking you would be wanting dates as the x component and speed as the y component, but I am having difficulty getting nice tilted markers using quiver.
I have a problem with wind direction :c
How about this--converting Date,Speed to X,Y, and the components of the "wind from DegreesCW from North" to math-like "wind vector towards degree CCW from East":
WindDirMath = 90-(WindDirection+180); % Switch dir between "From degN" and "Toward"
Uscale = 1;
quiver(Date,Speed,Uscale*cos(WindDirMath*pi/180),sin(WindDirMath*pi/180)
Note that to get the U,V aspect ratios and angles right, you will have to choose a good Uscale factor to make speed plot properly on your time axis.
Thank your answer. It is very important.
I am trying to Quiver plot using my data set. Could you please correct it?
load jan.txt;
windDirection=jan(:,4);
windSpeed=jan(:,5);
time=jan(:,1);jan(:,2);jan(:,3);
%time=jan(:,1:3);%
figure;
quiver(time, zeros(size(time)), windSpeed.*sind(windDirection), windSpeed.*cosd(windDirection));
2022 1 1 58.5 4.39
2022 1 2 62.81 5.99
2022 1 3 69.56 5.83
2022 1 4 67 4.88
2022 1 5 110.44 2.09
2022 1 6 78.25 3.9
2022 1 7 69.69 4.26
2022 1 8 40.31 3.02
2022 1 9 58.81 3.69
2022 1 10 118.62 2.11
2022 1 11 125.12 2.11
2022 1 12 163.56 2.31
2022 1 13 197.88 2.56
2022 1 14 126.88 1.77
2022 1 15 75.06 1.72
2022 1 16 55.69 4.48
2022 1 17 62.5 5.11
2022 1 18 61.44 4.14
2022 1 19 44.81 4.49
2022 1 20 130.12 2.73
2022 1 21 255.25 1.59
2022 1 22 216 1.54
2022 1 23 141.62 1.45
2022 1 24 120.94 1.8
2022 1 25 93.25 2.52
2022 1 26 60.5 2.71
2022 1 27 49.88 3.48
2022 1 28 76.25 3.53
2022 1 29 108.25 3.03
2022 1 30 90.44 3.49
2022 1 31 76.75 4.6
Replace
time=jan(:,1);jan(:,2);jan(:,3);
with
time = datetime(jan(:,1), jan(:,2), jan(:,3)];
Note that you might need a somewhat new version of MATLAB in order to be able to use datetime on the x axis in a quiver() plot.
Thank your responce with instructions. Replaced with datetime. But same result. I will try with another version.
Kind Regard,INDIKA
jan = [
2022 1 1 58.5 4.39
2022 1 2 62.81 5.99
2022 1 3 69.56 5.83
2022 1 4 67 4.88
2022 1 5 110.44 2.09
2022 1 6 78.25 3.9
2022 1 7 69.69 4.26
2022 1 8 40.31 3.02
2022 1 9 58.81 3.69
2022 1 10 118.62 2.11
2022 1 11 125.12 2.11
2022 1 12 163.56 2.31
2022 1 13 197.88 2.56
2022 1 14 126.88 1.77
2022 1 15 75.06 1.72
2022 1 16 55.69 4.48
2022 1 17 62.5 5.11
2022 1 18 61.44 4.14
2022 1 19 44.81 4.49
2022 1 20 130.12 2.73
2022 1 21 255.25 1.59
2022 1 22 216 1.54
2022 1 23 141.62 1.45
2022 1 24 120.94 1.8
2022 1 25 93.25 2.52
2022 1 26 60.5 2.71
2022 1 27 49.88 3.48
2022 1 28 76.25 3.53
2022 1 29 108.25 3.03
2022 1 30 90.44 3.49
2022 1 31 76.75 4.6];
windDirection=jan(:,4);
windSpeed=jan(:,5);
time = datetime(jan(:,1), jan(:,2), jan(:,3));
sdn = datenum(time);
quiver(sdn, zeros(size(time)), windSpeed.*sind(windDirection), windSpeed.*cosd(windDirection));
xlim([sdn(1), sdn(end)])
datetick('x', 1)

Connectez-vous pour commenter.

Renda Mohammedjuhar
Renda Mohammedjuhar le 18 Avr 2019

0 votes

Hi I need help! I want to write a Matlab code for a wind speed that varies in seconds between some values for one day in matrix and use it for simulink model of wind power,like the matrix is mx1 matrix where m is seconds thanks
Robert Daly
Robert Daly le 30 Nov 2023
Modifié(e) : Robert Daly le 30 Nov 2023
I wrote this function that gives similar output.
The arrows go a bit wierd if you zoom in so it is best to plot only what you want to show in your plot. Does anyone have feedback on how I might fix that?
If you are doing subplots you can give the figure handle as a the first argument so that it will plot in that subplot.
A 5th optional parameter will plot only every nth arrow, to stop it being crowded with dense data.
If you are keen you could change the shape of the arrow by editing this line
[theta,rho]=cart2pol([1,0.5,0.5,-1,-1,0.5,0.5],[0,0.5,0.25,0.25,-0.25,-0.25,-0.5]);
time = datetime("today")-14:datetime("today");
speed = rand(size(time));
dir = linspace(0,360,length(time));
figure
plot_wind(time,speed,dir);
function h = plot_wind(varargin)
if size(varargin,2)==2
Time=1:length(varargin{1});
WindSpd=varargin{1};
WindDir=varargin{2};
h=axes;
Skip=1;
hl = plot(WindSpd);
elseif size(varargin,2)==3
Time=varargin{1};
WindSpd=varargin{2};
WindDir=varargin{3};
Skip=1;
h=axes;
hl = plot(Time,WindSpd);
elseif size(varargin,2)==4
h=varargin{1};
Time=varargin{2};
WindSpd=varargin{3};
WindDir=varargin{4};
Skip=1;
hl = plot(h,Time,WindSpd);
elseif size(varargin,2)==5
h=varargin{1};
Time=varargin{2};
WindSpd=varargin{3};
WindDir=varargin{4};
Skip=varargin{5};
hl = plot(h,Time,WindSpd);
end
set(hl,'ZData', zeros(size(Time)));
WindowSize=get(gcf,'Position');%[left bottom width height]
AxesSize=get(h,'Position');%[left bottom width height]
xscalefactor=1.5*diff(get(h,'xlim'))*0.03*WindowSize(4)/WindowSize(3)*AxesSize(4)/AxesSize(3);
yscalefactor=1.5*diff(get(h,'ylim'))*0.03;
[theta,rho]=cart2pol([1,0.5,0.5,-1,-1,0.5,0.5],[0,0.5,0.25,0.25,-0.25,-0.25,-0.5]);
for p=1:Skip:length(WindDir)
[u,v]=pol2cart(theta-pi/2+WindDir(p).* pi ./ 180,rho);
c=hsv(361);
hp = patch(-u.*xscalefactor+Time(p),v.*yscalefactor+WindSpd(p),c(int16(WindDir(p)+1),:));
set(hp, 'ZData', ones(size(u))*p);
end
end

Catégories

En savoir plus sur Vector Fields dans Centre d'aide et File Exchange

Question posée :

le 26 Mar 2017

Modifié(e) :

le 30 Nov 2023

Community Treasure Hunt

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

Start Hunting!

Translated by