function [u_final,v_final]=wind_decomposition(hwd,hws)

[li,colm]=size(hwd);
u_final=[];
v_final=[];
for col=1:colm
    u=[];
    v=[];
    
    wd=hwd(:,col);
    
    
    wd=deg2rad(wd);
    
    u_wd=find(wd<=pi/2);
    u(u_wd)=-sin(wd(u_wd));
    v(u_wd)=-cos(wd(u_wd));
    
    
    u_wd=find(wd > pi/2 & wd <= pi);
    temp=wd(u_wd)-pi/2;
    u(u_wd)=-cos(temp);
    v(u_wd)=sin(temp);
    
    u_wd=find(wd > pi & wd <= 3*pi/2);
    temp=wd(u_wd)-pi;
    u(u_wd)=sin(temp);
    v(u_wd)=cos(temp);
    
    u_wd=find(wd > 3*pi/2 & wd <=2* pi);
    temp=wd(u_wd)-3*pi/2;
    u(u_wd)=cos(temp);
    v(u_wd)=-sin(temp);
    
    u_wd=find(isnan(wd));
    u(u_wd)=NaN;
    v(u_wd)=NaN;
    
    u_final=[u_final u'];
    v_final=[v_final v'];
    
end

u_final=hws.*u_final;
v_final=hws.*v_final;