I have to interpolate wind directions. The data is given for every 1000 [ft]. for example:
%winddata input in feet en degrees
x=0:1000:10000;
grad=[340 350 360 1 10 20 30 35 34 36 38];
The interpolation works great, i use the function interp1. (please see code below.) However, the step from 360 degrees to 1 degrees is a problem. I want Matlab to interpolate from 360 to 1 degree directly (clockwise), instead of anticlockwise with the values degreasing from 360-359-358-...3-2-1. That doesnt make sense when you interpolate wind directions.
How can i command Matlab to repeate the x-axis and values every 360 degrees?
clear all;clc;
h=2000;
%winddata input in feet en degrees!
x=0:1000:10000;
degrees=[340 350 360 1 10 20 30 35 34 36 38];
%conversion to SI:
x=0.3048*x;
u=0:1:max(x);
yinterp1 = interp1(x,degrees,u,'linear');
figure(3)
plot(degrees,x,'bo',yinterp1,u,'-r')
xlabel('wind direction [degrees]')
ylabel('height [m]')
title 'windspeed lineair interpolated with function interp'

The problem is that Matlab, as smart as it is, doesn't realise that you're working with degrees, so therefore it sees no reason that 360 = 0. Therefore I believe your problem isn't with finding a way to repeat the plot every 360 degrees, but rather with the data you are feeding in to your interp1 function, as currently you are telling it there is a straight line between the points (0, 950) and (360, 750).
The easiest, but ugliest, method would be to just add 360 to your lower values, so your degrees vector read:
degrees = [340 350 360 361 370 380 390 395 394 396 398];
and then subtract 360 from your degrees and yinterp1 vectors:
clear all;clc;
h=2000;
%winddata input in feet en degrees!
x=0:1000:10000;
degrees=[340 350 360 361 370 380 390 395 394 396 398];
%conversion to SI:
x=0.3048*x;
u=0:1:max(x);
yinterp1 = interp1(x,degrees,u,'linear');
figure(3)
plot(degrees-360,x,'bo',yinterp1-360,u,'-r')
xlabel('wind direction [degrees]')
ylabel('height [m]')
title 'windspeed lineair interpolated with function interp'
xlim([-180 180]);
The obvious problem with this is it isn't able to be applied for all cases, but if you just need a one off, then it works well.
For a more generic solution you could have it so you manually enter a point below which values have 360 added to them:
clear all;clc;
h=2000;
% --------------------- Manual cutoff for rectification -------------------
limitDegrees = 180;
% -------------------------------------------------------------------------
%winddata input in feet en degrees!
x=0:1000:10000;
degrees=[340 350 360 1 10 20 30 35 34 36 38];
%conversion to SI:
x=0.3048*x;
u=0:1:max(x);
indecesTooSmall = find(degrees <= limitDegrees);
oneVec = zeros(size(degrees));
oneVec(indecesTooSmall) = 1;
vecToAdd = 360*ones(size(degrees));
vecToAdd = vecToAdd .* oneVec;
newDegrees = degrees + vecToAdd;
yinterp1 = interp1(x,newDegrees,u,'linear');
figure(3)
plot(newDegrees-360,x,'bo',yinterp1-360,u,'-r')
xlabel('wind direction [degrees]')
ylabel('height [m]')
title 'windspeed lineair interpolated with function interp'
xlim([-180 180]);
Both of the above solutions give the following:

EDIT: Substantially easier solution, just use rad2deg(unwrap(deg2rad(degrees))), or try to find an unwrap which works for degrees.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With