
fname='DIRECTORY';
filename='wheat_irr.nc';
ncdisp(fullfile(fname,filename));
wheat_irr =ncread(fullfile(fname,filename),'Band1');
filename='wheat_rain.nc';
ncdisp(fullfile(fname,filename));
wheat_rain =ncread(fullfile(fname,filename),'Band1');
wheat_coveragee=wheat_irr+wheat_rain;
wheat_coveragee(wheat_coveragee==0)=NaN;
wheat_coverage=fliplr(wheat_coveragee);
wheat_coverage=(wheat_coveragee)';
%%%%%%%%%%%%%%%%%%%%%%%%%%
load('DIRECTORY/input');
%%%%%%%%%%%%%%%%%%%%%%%%%%
VAR_2007=nan(360,720);
VAR_2007(61:335,:)=(PDSI_in_CROPLANDS_1900_2014(:,:,108));
VAR_2007_final=nan(360,720);
for i=1:360
    for j=1:720
        if ~isnan(wheat_coverage(i,j))
            VAR_2007_final(i,j)=VAR_2007(i,j);
        end
    end
end

k=0;
for i=1:360
    for j=1:720
        k=k+1;
        PDSI_2007(k,1)=lat_pdsi_360(i);
        PDSI_2007(k,2)=long_pdsi_720(j);
        PDSI_2007(k,3)=VAR_2007_final(i,j);
    end
end
PDSI_2007(sum(isnan(PDSI_2007), 2) == 1, :) = [];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
VAR_1998=nan(360,720);
VAR_1998(61:335,:)=(PDSI_in_CROPLANDS_1900_2014(:,:,99));
VAR_1998_final=nan(360,720);
for i=1:360
    for j=1:720
        if ~isnan(wheat_coverage(i,j))
            VAR_1998_final(i,j)=VAR_1998(i,j);
        end
    end
end

k=0;
for i=1:360
    for j=1:720
        k=k+1;
        PDSI_1998(k,1)=lat_pdsi_360(i);
        PDSI_1998(k,2)=long_pdsi_720(j);
        PDSI_1998(k,3)=VAR_1998_final(i,j);
    end
end
PDSI_1998(sum(isnan(PDSI_1998), 2) == 1, :) = [];
