%% scatterPlot

% Verify the calculation methods for the dunefoot position per transect
% area. Plot in map of the holland coastline.

%clear;
%close;
%clc;

%% GET computational methods

df_ver6 = load('D:\diama_ey\Desktop\Scripts Elly\new methodology\DF_2nd_deriv.mat');

%% Get data from jarkus

url             = jarkus_url;
id              = nc_varget(url,'id');
areacode        = nc_varget(url,'areacode');
areaname        = nc_varget(url,'areaname');
lat             = nc_varget(url,'lat',[0,0],[-1,-1]);
lon             = nc_varget(url,'lon',[0,0],[-1,-1]);
xRSP            = nc_varget(url,'cross_shore');

%% Retrieve data dunefoot

url_df = 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/strandlijnen/strandlijnen.nc';

year        = round(1970 + nc_varget(url_df,'time')/365);
yrs         = 1965;
start_year  = find(year == yrs)-1;
yrs2        = year(end);
n_year      = yrs2-yrs+1;

id_DF   = nc_varget(url_df,'id');
DF      = nc_varget(url_df,'DF',[0 start_year],[-1 n_year]);
DF_x    = nc_varget(url_df,'DF_x',[0 start_year],[-1 n_year]);
DF_y    = nc_varget(url_df,'DF_y',[0 start_year],[-1 n_year]);
DF_lat  = nc_varget(url_df,'DF_lon',[0 start_year],[-1 n_year]);
DF_lon  = nc_varget(url_df,'DF_lat',[0 start_year],[-1 n_year]);

[idID_STa, idID_STb] = ismember(id,id_DF);
idID_STb(idID_STb == 0) = [];     

DF_filt(:,:)     = DF(idID_STb,:);
DF_filt_x(:,:)   = DF_x(idID_STb,:);
DF_filt_y(:,:)   = DF_y(idID_STb,:);
DF_filt_lat(:,:) = DF_lat(idID_STb,:);
DF_filt_lon(:,:) = DF_lon(idID_STb,:);

%% Calculate X_rsp positions for the strandlijnen

[~, n] = size(DF);

DF_cross = zeros(size(DF_filt));

latdum = lat(idID_STa,:);
dd=[];
for i = 1:n;
    for j = 1:length(idID_STb)
        if ~isnan(DF_filt_lat(j,i))
            dummy    = abs(latdum(j,:) - DF_filt_lat(j,i));
            dd=[dd; min(dummy)];
            id_cross = find(dummy == min(dummy));
            DF_cross(j,i) = xRSP(id_cross);
        else
            DF_cross(j,i) = NaN;
        end
    end
end

%% Jarkus dunefoot data
url_jks = 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/DuneFoot/DF.nc';

for i = 1:n
    
    year            = round(1970 + nc_varget(url_df,'time')/365);
    yrs             = 1964 + i;
    start_year      = find(year == yrs)-1;
    yrs2            = year(end);
    n_year          = yrs2-yrs+1;
    
    df_uppermkl     = nc_varget(url_jks,'dune_foot_upperMKL_cross',[start_year,0],[1,-1]);
    df_threenap     = nc_varget(url_jks,'dune_foot_threeNAP_cross',[start_year,0],[1,-1]);
    
    DF_upperMKL(:,i)     = df_uppermkl(idID_STa);
    DF_threeNAP(:,i)     = df_threenap(idID_STa);
    
end

%% second derivative method dunefoot data

for i = 1:n
        
    xdf_m1(:,i)     = df_ver6.xDF(i,idID_STa);
    zdf_m1(:,i)     = df_ver6.zDF(i,idID_STa);
    
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% choose the dunefoot
dfcalc = xdf_m1;
dfcalc_3 = DF_threeNAP;    %% xdf_m1 % DF_upperMKL; DF_threeNAP;  % cross shore direction 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Look at data per pre-defined area

areacode2 = areacode(idID_STa);
areaname2 = areaname(idID_STa,:);

[kv, m, dummy]  = unique(areacode2);
n               = vertcat(m(2:end)-1,length(areacode2));
x = -1000:100:1000;
y = x;

% Create separate matrices for the coastal areas
% Calculation method: second derivatives

%% Holland figure

f2 = figure;
set(f2,'color','white');

url2 = 'http://opendap.deltares.nl/thredds/dodsC/opendap/deltares/landboundaries/holland_fillable.nc';
x = nc_varget(url2, 'lon');
y = nc_varget(url2, 'lat');
P1 = plot(x,y,'k');
hold on;

xlim([3 6.5])
ylim([51 54]);

xlabel('Longitude','FontWeight','Bold','Fontsize',16)
ylabel('Latitude','FontWeight','Bold','Fontsize',16)

if sum(sum(dfcalc(~isnan(dfcalc)))) == sum(sum(DF_upperMKL(~isnan(DF_upperMKL))))
    title('Upper MKL method','FontWeight','Bold')
elseif sum(sum(dfcalc(~isnan(dfcalc)))) == sum(sum(DF_threeNAP(~isnan(DF_threeNAP))))
    title('Three NAP method','FontWeight','Bold')
elseif sum(sum(dfcalc(~isnan(dfcalc)))) == sum(sum(xdf_m1(~isnan(xdf_m1))))
    title('second derivative method','FontWeight','Bold','FontSize',18)
end

DAR = get(gca,'DataAspectRatio');
set(gca,'DataAspectRatio',[DAR(1) DAR(2)/1.2 DAR(3)]);
set(gca,'FontSize',16)
set(gcf,'Position',[1921 -172 1920 1004]);


%% Axes 1: Schiermonnikoog

A1 = axes('Units','centimeters','Position',[32.5 17.5 2.5 2.5],'Box','on');

i = 1;

    DF_msrd = DF_cross(m(i):n(i),:);  % matrix for one area only 
    DF_comp = dfcalc(m(i):n(i),:);

    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]); %the values of DF_msrd in a raw
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));    
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)


set(A1,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Schiermonnikoog' '.png'])
    %close()
    

%% Axes 2: Ameland

A2 = axes('Units','centimeters','Position',[30.5 21.5 2.5 2.5],'Box','on');

i = 2;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc_3(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A2,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -600; xmax = 600;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('Dune foot (m) - New methodology','FontSize',14);
    ylabel('Dune foot (m) - Visual observations','FontSize',14);
    title('Ameland','FontSize',16)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',14); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Ameland' '.png'])
    %close()

%% Axes 3: Terschelling

A3 = axes('Units','centimeters','Position',[28.5 17 2.5 2.5],'Box','on');

i = 3;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A3,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Terschelling' '.png'])
    %close()

%% Axes 4: Vlieland

A4 = axes('Units','centimeters','Position',[25.5 20 2.5 2.5],'Box','on');

i = 4;

DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1200;
    xmax = 1200;
    
    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A4,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Vlieland' '.png'])
    %close()


%% Axes 5: Texel

A5 = axes('Units','centimeters','Position',[22.5 17.5 2.5 2.5],'Box','on');

i = 5;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1200;
    xmax = 1200;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A5,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Texel' '.png'])
    %close()


%% Axes 6: Noord-Holland

A6 = axes('Units','centimeters','Position',[22.5 14.5 2.5 2.5],'Box','on');

i = 6;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A6,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Noord-Holland' '.png'])
    %close()

%% Axes 7: Rijnland

A7 = axes('Units','centimeters','Position',[21.5 11.5 2.5 2.5],'Box','on');

i = 7;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A7,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Rijnland' '.png'])
    %close()
    
%% Axes 8: Delfland

A8 = axes('Units','centimeters','Position',[24.5 10 2.5 2.5],'Box','on');

i = 8;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A8,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Delfland' '.png'])
    %close()

%% Axes 9: Voorne

A9 = axes('Units','centimeters','Position',[23.5 7.25 2.5 2.5],'Box','on');

i = 9;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A9,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Voorne' '.png'])
    %close()
    
%% Axes 10: Goeree

A10 = axes('Units','centimeters','Position',[18.5 8.75 2.5 2.5],'Box','on');

i = 10;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;
    
    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A10,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Goeree' '.png'])
    %close()
    
%% Axes 11: Schouwen

A11 = axes('Units','centimeters','Position',[21.5 4.5 2.5 2.5],'Box','on');

i = 11;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A11,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Schouwen' '.png'])
    %close()
    
%% Axes 12: Walcheren

A12 = axes('Units','centimeters','Position',[18 3.5 2.5 2.5],'Box','on');

i = 12;

    DF_msrd = DF_cross(m(i):n(i),:);
    DF_comp = dfcalc(m(i):n(i),:);
    
    % Filter biased values
    
    DF_comp(isnan(DF_msrd)) = NaN;
    
    nonzero = find(DF_msrd);
    
    DF_msrd_corr            = reshape(DF_msrd(nonzero),[length(nonzero),1]);
    id_nan                  = isnan(DF_msrd_corr);
    DF_msrd_corr(id_nan)    = 0;
    id_zero                 = (DF_msrd_corr == 0);
    DF_msrd_corr(id_zero)   = [];
    
    DF_comp_corr            = reshape(DF_comp(nonzero),[length(nonzero),1]);
    DF_comp_corr(id_nan)    = 0;
    DF_comp_corr(id_zero)   = [];
    
    id_nan2                             = isnan(DF_comp_corr);
    DF_comp_corr(id_nan2)               = [];
    DF_msrd_corr(id_nan2)               = [];
    
    % delete NaNs [gio]
    DF_comp_corr = DF_comp_corr(~isnan(DF_comp_corr));
    DF_msrd_corr = DF_msrd_corr(~isnan(DF_msrd_corr));
    
    % corrcoef(i) = corr(DF_comp_corr,DF_msrd_corr);
    C    = cov(DF_comp_corr,DF_msrd_corr); % no stat. gio.
    corrcoef(i) = C(2)/(std(DF_comp_corr)*std(DF_msrd_corr)); % no stat. gio.
    
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor',[.6 .6 .6],'SizeData',10);
    hold on;
    
    xmin = -1000;
    xmax = 1000;

    xlim([xmin xmax])
    ylim([xmin xmax])
    
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    
set(A12,'XTickLabel','','YTickLabel','','Box','on');

% plot as a separate graph
    fs = figure();
    scatter(DF_comp_corr,DF_msrd_corr,'o','MarkerEdgeColor',[.2 .2 .2],'MarkerFaceColor',[.5 .5 .5],'LineWidth',.5,'SizeData',10);
    hold on;
    xmin = -1000; xmax = 1000;
    xlim([xmin xmax]); ylim([xmin xmax])
    plot3([xmin xmax],[xmin xmax],[1 1],'Color','k');
    text(xmin/2,3*xmin/4,1,['R=',num2str(corrcoef(i),'%5.3f')],'FontSize',14)
    xlabel('DF second derivative','FontSize',12);
    ylabel('DF visual method','FontSize',12);
    title('second derivative method','FontSize',14)
    set(fs,'Position',[5 35 1040 760]); set(gca,'FontSize',12); grid on
    %print('-dpng','-r300',['testPerformance\scatterPlot' filesep '2ndVSvisual_' 'Walcheren' '.png'])
    %close()
    
%% Plot connection lines

C = get(f2,'Children');

hold(C(end),'on');

plot(C(end),[6.22 6.23],[53.35 53.49],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[5.77 5.75],[53.46 53.6],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[5.4 5.35],[53.25 53.4],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[4.86 4.94],[53.38 53.25],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[4.48 4.83],[53.2 53.1],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[4.48 4.68],[52.78 52.7],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[4.28 4.53],[52.38 52.36],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[4.43 4.23],[52.17 52.06],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[4.25 4.07],[51.78 51.9],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[3.7 3.95],[52.0 51.81],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[4.07 3.75],[51.55 51.71],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

plot(C(end),[3.38 3.52],[51.4 51.53],'-ko','MarkerEdgeColor',[.6 .6 .6],'MarkerFaceColor','k','LineWidth',1.25);

%% Print figure
% if sum(sum(dfcalc(~isnan(dfcalc)))) == sum(sum(DF_upperMKL(~isnan(DF_upperMKL))))
%     export_fig ..\testPerformance\scatterPlot\Correlation_upperMKL_Hollandmap.png -nocrop
% elseif sum(sum(dfcalc(~isnan(dfcalc)))) == sum(sum(DF_threeNAP(~isnan(DF_threeNAP))))
%     export_fig ..\testPerformance\scatterPlot\Correlation_threenap_Hollandmap.png -nocrop
% elseif sum(sum(dfcalc(~isnan(dfcalc)))) == sum(sum(xdf_m1(~isnan(xdf_m1))))
%     export_fig ..\testPerformance\scatterPlot\secderiv_Hollandmap.png -nocrop
% end

%export_fig testPerformance\scatterPlot\VISvs2nd.png -nocrop
