numBins = 100;

cycleNum = 3;
[indexes, edges] = discretize(cycle{1,cycleNum}.pressureDBar, numBins);
for i=1:numBins
    pressureMeanIncr(i) = mean(cycle{1,cycleNum}.pressureDBar(indexes(i)));
    vrsMeanIncr(i) = mean(cycle{1,cycleNum}.vrsVolts(indexes(i)));
end

cycleNum = cycleNum + 1;
[indexes, edges] = discretize(cycle{1,cycleNum}.pressureDBar, numBins);
for i=1:numBins
    pressureMeanDecr(i) = mean(cycle{1,cycleNum}.pressureDBar(indexes(i)));
    vrsMeanDecr(i) = mean(cycle{1,cycleNum}.vrsVolts(indexes(i)));
end

hyst = vrsMeanIncr - vrsMeanDecr;
figure
plot(pressureMeanIncr, hyst, 'g');
ax = gca;
ax.YAxis.Exponent = -3;
ylabel('Vrs Incr - Vrs Decr')
hold on
yyaxis right
hold on
plot(pressureMeanIncr, vrsMeanIncr, '-+b', pressureMeanDecr, vrsMeanDecr, '-or')
plot(cycle{cycleNum - 1}.pressureDBar, cycle{cycleNum -1}.vrsVolts, '-y')
plot(cycle{cycleNum}.pressureDBar, cycle{cycleNum}.vrsVolts, '-c')
ylabel('Vrs')
xlabel('Binned Pressure (dBar)')
legend('Hysteresis', 'Binned Increasing P', 'Binned Decreasing P', ...
    'Increasing P', 'Decreasing P')

