-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluofit7.m
51 lines (43 loc) · 1.54 KB
/
fluofit7.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
%do a chi^2 fiting of miltiple fluorolog spectra which include an
%imported bound and unbound spectra
%Zhiliang Gong, 9/4/2012
function tdata = fluofit7(tdata,U,B)
colors = 'kgbrcmykgbrcmy';
b = 0:0.01:1;%fitting steps
[n,m] = size(tdata.aSR);
k = length(b);
chi_sq = zeros(k,m-2);%reduced chi^2 value
for i = 1:k
temp = b(i)*B+(1-b(i))*U;
chi_sq(i,:) = sum((tdata.aSR(:,2:(m-1))-repmat(temp,1,m-2)).^2./(tdata.SRstd(:,2:(m-1))).^2);
end
chi_sq = chi_sq/(n-1-1);%calculate the reduced chi^2 values
figure;
plot(b,chi_sq,'.','color','r');
xlabel('bound fraction');
ylabel('reduced chi^2 value');
title('Chi^2 value - bound fraction relation');
S = zeros(n,m-2);
rchi_sq = min(chi_sq);%minimum reduced chi^2 values for each fitting spectrum
bind_frac = zeros(1,m);
bind_frac(1) = 0;
bind_frac(end) = 1;
tdata.rchi_sq = rchi_sq;%add reduced chi^2 to data structure
for i = 1:(m-2)
j = find(rchi_sq(i)==chi_sq(:,i));
bind_frac(i+1) = b(j(1));
S(:,i) = b(j(1))*B+(1-b(j(1)))*U;
figure;
errorbar(tdata.wl,tdata.aSR(:,i+1),tdata.SRstd(:,i+1)/2,'o','color','b');
hold on;
plot(tdata.wl,S(:,i),'-','LineWidth',2,'color','r');
xlabel('wavelength (nm)');
ylabel('S/R');
s = strcat('Lipid: ', sprintf('%02d',tdata.lcons(i+1)), 'uM, Protein: ', sprintf('%02d',tdata.pcons(i+1)), 'nM, Buffer:', tdata.buffer, ', PS Percentage: ', sprintf('%02d',tdata.ps*100),'%');
title(s);
legend('data','fit');
hold off;
pause;
end
tdata.aSR_fit = S;
tdata.bind_frac = bind_frac;