forked from helgestein/htAx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallbackSlopeFit.m
89 lines (70 loc) · 2.99 KB
/
callbackSlopeFit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function callbackSlopeFit(obj, evt, lower, ECHandles)
%CALLBACKSLOPEFIT fits a line through the selected data in a CV plot
fECPlot = ECHandles.fECPlot;
ECInfo = fECPlot.UserData;
valSlider1 = ECInfo.valSliderFit1;
valSlider2 = ECInfo.valSliderFit2;
ECData = ECInfo.ECData;
genIndex = ECInfo.selectedPlotGenIndex;
dispIndex = ECInfo.selectedPlotDispIndex;
hEditOffset = ECHandles.editOffset;
ECPlotInfo = ECInfo.ECPlotInfo;
plotPotential = ECData(:, genIndex * 2 - 1);
plotCurrent = log10(abs(ECData(:, genIndex * 2))) + ...
hEditOffset.UserData * (dispIndex - 1);
waterfallPlot = ECInfo.waterfallPlot;
lobfData = ECInfo.lobfData;
[slope, intercept] = getFit(valSlider1, valSlider2, ...
plotPotential, plotCurrent, ECPlotInfo(genIndex, 4));
if lower == 1
if ishandle(ECInfo.lowLobf) == 1
delete(ECInfo.lowLobf);
end
ECInfo.lowLobf = ...
plotLobf(waterfallPlot.dataAxes, ECHandles.fECPlot, ...
slope, intercept);
lobfData(genIndex, 1) = slope;
lobfData(genIndex, 2) = intercept;
lobfData(genIndex, 5) = 1;
set(ECHandles.textLowerSlope, 'String', ...
strcat({'y = '}, num2str(slope), {'x + '}, num2str(intercept)));
else
if ishandle(ECInfo.highLobf) == 1
delete(ECInfo.highLobf);
end
ECInfo.highLobf = ...
plotLobf(waterfallPlot.dataAxes, ECHandles.fECPlot, ...
slope, intercept);
lobfData(genIndex, 3) = slope;
lobfData(genIndex, 4) = intercept;
lobfData(genIndex, 6) = 1;
set(ECHandles.textHigherSlope, 'String', ...
strcat({'y = '}, num2str(slope), {'x + '}, num2str(intercept)));
end
ECInfo.lobfData = lobfData;
fECPlot.UserData = ECInfo;
function [slope, intercept] = getFit(valSlider1, valSlider2, ...
plotPotential, plotCurrent, decrease)
if valSlider1 < valSlider2
if decrease == -1
lowIndex = findClosestPotDecrease(valSlider2, plotPotential);
highIndex = findClosestPotDecrease(valSlider1, plotPotential);
else
lowIndex = findClosestPot(valSlider1, plotPotential);
highIndex = findClosestPot(valSlider2, plotPotential);
end
else
if decrease == -1
lowIndex = findClosestPotDecrease(valSlider1, plotPotential);
highIndex = findClosestPotDecrease(valSlider2, plotPotential);
else
lowIndex = findClosestPot(valSlider2, plotPotential);
highIndex = findClosestPot(valSlider1, plotPotential);
end
end
linearFit = polyfit(plotPotential(lowIndex:highIndex), ...
plotCurrent(lowIndex:highIndex), 1);
slope = linearFit(1);
intercept = linearFit(2);
end
end