function [xx, grd_1] =  func_calc_slope(slope, sdata)

    ngroups = 8;
    x = slope; y = sdata;

    [x_sort, ind] = sort(x(:)); y_sort = y(ind);

    x_edge = quantile(x_sort,ngroups-1);
    [counts, Id] = histc(x_sort,[-inf; x_edge(:); inf]);
    
    for igrp = 1:ngroups
        
        x2d_g = x_sort(Id==igrp);y2d_g = y_sort(Id==igrp);
        x2d_gv = x2d_g(~isnan(x2d_g) & ~isnan(y2d_g)); y2d_gv = y2d_g(~isnan(x2d_g) & ~isnan(y2d_g));
        p = polyfit(x2d_gv,y2d_gv,1);
        grd_1(igrp) = p(1);
        xx(igrp) = mean(x2d_g);
    end

end