-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitb.m
43 lines (37 loc) · 965 Bytes
/
fitb.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
function nb = fitb( ps, b )
%fitb, find the best binding coefficients
% fit the binding coefficients to a binding model
% ps is the [PS]
% b is the binding coefficients
if ps(1) == 0
ps = ps(2:end);
b = b(2:end);
end
dev = zeros(size(0.1:0.01:1));
k = 0;
for mb = 0.1:0.01:1
k = k + 1;
tempb = mb*b;
P = polyfit(log(ps),log(1./(1-tempb)),1);
dev(k) = sum((P(2)*ps + P(1) - log(1./(1-tempb))).^2);
end
figure;
plot(0.1:0.01:1,dev);
xlabel('Max bound fraction');
ylabel('deviation from binding model');
title('binding model fitting');
pause;
close;
[mindev, k] = min(dev) % k is the index of the optimal binding coefficient
nb = mb(k)*b;
P = polyfit(log(ps),log(1./(1-nb)),1);
figure;
plot(log(ps),log(1./(1-nb)),'o');
hold on;
plot(-1:0.01:2.5, P(2)*(-1:0.01:2.5) + P(1),'-r');
legend('data','fit');
hold off;
xlabel('[PS]/\muM');
ylabel('log(1/(1-b))');
title('binding model fitting');
end