Using METAR data in Matlab
古いコメントを表示
I have METAR data that I need to use for finding the wind speeds at certain times throughout the day. Currently it is being imported into MATLAB as an excel file, where the date and wind speed are in separate columns. They each are saved into their own variables.
I need to take the wind data and separate that out into direction of wind and speed of wind. Currently it is being read as:
13008KT
130 is the direction the wind is blowing, 08 is the speed, KT stands for knots - the unit it is being measured in
I need to take this and separate it into two different variables. One which contains only the direction that the wind is blowing, and another that contains the wind speed. I would also need to do this with a wind that is gusting. This would be read as
13008G18KT
This would need to be divided into 3 different variables, one for the direction of the wind, one for the speed of the wind, and one for the gust speed of the wind.
Any help would be greatly appreciated
回答 (1 件)
Star Strider
2014 年 6 月 4 日
This seems to do what you want:
data = {'13008KT', '08009KT', '13009KT', '13008KT', '13008G18KT'} ;
vde = regexp(data, 'KT(\w*)') % Find occurrences of ‘KT’
ge = regexp(data, 'G(\w*)') % Find occurrences of ‘G’
for k1 = 1:size(vde,2)
vdix = vde{k1}; % Define starting index for numeric data
gvel(k1,:) = 0; % All gusts initially zero
if ~isempty(ge{k1}) % Check for gust
vdix = min(vde{k1},ge{k1}); % Redefine number start
gix = vde{k1}; % Define gust start
gvel(k1,:) = str2num(data{k1}(vdix+1:gix-1));
end
veldir(k1,:) = data{k1}(1:vdix-1); % Get velocity & direction
wdvg(k1,:) = [str2num(veldir(k1,1:3)) str2num(veldir(k1,4:5)) gvel(k1,:)];
end
The gvel assignments first initially set all gusts to zero, then if one is discovered, detects and substitutes its value for the default.
The wdvg array has in order wind direction, velocity, and gust velocity.
It should be robust for the data you specified, but if any of the wind or gust velocities are greater than 99KT, the code could fail.
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!