measured = load('hdrCalGamma_1x1');

g0 = 2.6337 %mean(singleLEDGamma(:,1))
maxLuminance = max(measured.XYZ(:,2));

LCDLevels = measured.inputs(:,1);
LEDLevels = measured.inputs(:,2);
measuredLuminance = measured.XYZ(:,2);

g = fminsearch(@(g) sum((measuredLuminance-hdrGetLuminance(g,LCDLevels,LEDLevels,maxLuminance)).^2), g0)


sqe_g0 = (measuredLuminance-hdrGetLuminance(g0,LCDLevels,LEDLevels,maxLuminance)).^2;
sqe_g = (measuredLuminance-hdrGetLuminance(g,LCDLevels,LEDLevels,maxLuminance)).^2;

ploterror(LCDLevels,LEDLevels,sqe_g0);
title(['meaned gamma = ',num2str(g0)]);

ploterror(LCDLevels,LEDLevels,sqe_g);
title(['fminsearched gamma = ',num2str(g)]);

mse_g0 = sum(sqe_g0)/length(sqe_g0)
mse_g = sum(sqe_g)/length(sqe_g)
