close all

i = 1;

[minValue, closestIndex] = min(abs(profile(i).ptsDT - profile(i).optodeDT.'))
    profile(i).tempDiff = profile(i).ptsT(closestIndex) - profile(i).optodeT;
    profile(i).ptsTGradient = profile(i).ptsT(1:end-1) - profile(i).ptsT(2:end);
    profile(i).optodeTGradient = profile(i).optodeT(1:end-1) - profile(i).optodeT(2:end);
    profile(i).ptsMeanT = mean(profile(i).ptsT);
    
    figure
    plot(profile(i).ptsDT, profile(i).ptsT);
    hold on
    plot(profile(i).optodeDT, profile(i).optodeT)
    ylim([(profile(i).ptsMeanT - 0.5) (profile(i).ptsMeanT + 0.5)]);
    legend('CTD T', 'Optode T');
    hold off
    
    figure
    hold on
    plot(profile(i).optodeDT, profile(i).tempDiff, 'r+-');
    plot(profile(i).ptsDT(1:end-1), profile(i).ptsTGradient, 'go-')
    plot(profile(i).ptsDT, profile(i).ptsT - profile(i).ptsMeanT)
    ylim([-0.1 0.1]);
    legend('CTD T - Optode T', 'Optode Temp Gradient', 'CTD T - mean');
    hold off
