Plot of windspeed and wind direction in time series
조회 수: 120 (최근 30일)
이전 댓글 표시
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
Tim
2018년 3월 27일
Did you manage to get a script to plot your data like the output from Weatherunderground? Struggling with Quiver too
답변 (3개)
Walter Roberson
2017년 3월 26일
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
indika kathaluwa weligamage
2023년 9월 30일
Dear Walter Roberson
Thank your responce with instructions. Replaced with datetime. But same result. I will try with another version.
Kind Regard,INDIKA
Walter Roberson
2023년 9월 30일
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)
Renda Mohammedjuhar
2019년 4월 18일
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
댓글 수: 0
Robert Daly
2023년 11월 30일
편집: Robert Daly
2023년 11월 30일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!