figure
hold on
for i=1:50
    indexes = find(dataTable{1}.StepNum == i);
    plot(dataTable{1}.dtLV(indexes), dataTable{1}.pressureDBar(indexes));
end

%

polyOrder = 3;
close all

for i=3:2:50
    figure
    hold on

    indexes = find(dataTable{1}.StepNum == i);
    x = dataTable{1}.pressureDBar(indexes);
    y = dataTable{1}.vrsVolts(indexes);

    lastwarn('')
    polyFitVals = polyfit(x, y, polyOrder);
    [warnMsg, warnId] = lastwarn;
    if ~isempty(warnMsg)
       pause
    end

    yFit = polyval(polyFitVals, x);
    maxResidual = max(abs(yFit - y));
    plot(x, y, x, yFit);
    titleString1 = strcat('Max incr residual: ', compose("%.3e", maxResidual));

    indexes = find(dataTable{1}.StepNum == i+1);
    x2 = dataTable{1}.pressureDBar(indexes);
    y2 = dataTable{1}.vrsVolts(indexes);
    polyFitVals = polyfit(x2, y2, polyOrder);
    yFit = polyval(polyFitVals, x2);
    maxResidual = max(abs(yFit - y2));
    plot(x2, y2, x2, yFit);
    titleString2 = strcat('Max decr residual: ', compose("%.3e", maxResidual));

    x3 = [x; x2];
    y3 = [y; y2];
    polyFitVals = polyfit(x3, y3, polyOrder);
    yFit = polyval(polyFitVals, x3);
    maxResidual = max(abs(yFit - y3));
    plot(x3, y3, x3, yFit);
    titleString3 = strcat('Max both ways residual: ', compose("%.3e", maxResidual));
    title([titleString1, newline newline titleString2 newline titleString3])
end

%

cycleNum = 0;
diffNum = 6;

dataTable{1}.cycleNum = zeros(length(dataTable{1}.pressureDBar),1);
pressureDBar = dataTable{1}.pressureDBar;

for i=1+diffNum:length(pressureDBar)
    diff = pressureDBar(i-diffNum)-pressureDBar(i);
    if( abs(diff) > 1.0)
        if(dataTable{1}.cycleNum(i-1)) == 0
            i
            cycleNum = cycleNum + 1;
        end
        dataTable{1}.cycleNum(i) = cycleNum;
    else
        dataTable{1}.cycleNum(i-6:i) = 0;
    end
end

figure
for i=1:2:max(dataTable{1}.cycleNum)
    indexes = find(dataTable{1}.cycleNum == i);
    plot(dataTable{1}.pressureDBar(indexes))
end

figure
for i=2:2:max(dataTable{1}.cycleNum)
    indexes = find(dataTable{1}.cycleNum == i);
    plot(dataTable{1}.pressureDBar(indexes))
end

%

figure
hold on
for i=1:26
    plot(cycle{i}.xIncr, cycle{i}.yIncr, 'g')
    plot(cycle{i}.xIncr, cycle{i}.yFitIncr, 'b')
    pause(1)
end

for i=1:26
    plot(cycle{i}.xDecr, cycle{i}.yDecr, 'y')
    plot(cycle{i}.xDecr, cycle{i}.yFitDecr, 'r')
    pause(1)
end

%

figure
hold on
colormap(jet);
colorValue = -5;

for i=1:length(cycle)   
    x = datenum(cycle{i}.dtIncr)';
    y = cycle{i}.pIncr' ;
    z = cycle{i}.VrsIncr';

%    lineColor = colorValue * ones(1, length(x));
    plot3(x, y, z, 'g');
    z = cycle{i}.VrsFitIncr';
    plot3(x, y, z, 'b');
 
 %   patch([x nan], [y nan], [z nan], [lineColor nan],'EdgeColor','interp','FaceColor','none')
end
set(gca, 'ydir', 'reverse');
zLimits = zlim;
set(gca, 'ztick', [zLimits(1):0.001:zLimits(2)+.001]);
view(3);
datetick('x', 'mmmdd HH:MM')
grid on
colorbar;
xStart = datenum(cycle{1}.dtIncr(1));
xEnd = datenum(cycle{length(cycle)}.dtIncr(end));
xlim([xStart xEnd]);

%

figure
for