% This script calculates the concentration in a sample from an absorbance
% spectrum the sample, standardspectrums and a negative control. 
% Experimental and predicted data is fitted in an ordinary least
% squares manner. concInExtract is the concentration in the extract 
% and concInCulture is the concentration in the cell culture that
% the metabolite was extracted from.
wv=230:350;
%230-350 nm
standardAbs=[0.567000000000000,0.632000000000000,0.598000000000000,0.287000000000000,0.104000000000000,0.0550000000000000;0.562000000000000,0.628000000000000,0.593000000000000,0.284000000000000,0.103000000000000,0.0550000000000000;0.553000000000000,0.620000000000000,0.585000000000000,0.280000000000000,0.102000000000000,0.0550000000000000;0.538000000000000,0.606000000000000,0.570000000000000,0.274000000000000,0.100000000000000,0.0540000000000000;0.512000000000000,0.582000000000000,0.545000000000000,0.262000000000000,0.0960000000000000,0.0530000000000000;0.478000000000000,0.550000000000000,0.512000000000000,0.245000000000000,0.0910000000000000,0.0510000000000000;0.440000000000000,0.515000000000000,0.475000000000000,0.227000000000000,0.0840000000000000,0.0480000000000000;0.395000000000000,0.473000000000000,0.431000000000000,0.206000000000000,0.0770000000000000,0.0440000000000000;0.344000000000000,0.424000000000000,0.379000000000000,0.181000000000000,0.0680000000000000,0.0400000000000000;0.287000000000000,0.370000000000000,0.322000000000000,0.153000000000000,0.0570000000000000,0.0350000000000000;0.240000000000000,0.325000000000000,0.276000000000000,0.129000000000000,0.0470000000000000,0.0300000000000000;0.208000000000000,0.293000000000000,0.244000000000000,0.112000000000000,0.0400000000000000,0.0270000000000000;0.182000000000000,0.267000000000000,0.217000000000000,0.0980000000000000,0.0350000000000000,0.0240000000000000;0.155000000000000,0.239000000000000,0.189000000000000,0.0840000000000000,0.0300000000000000,0.0220000000000000;0.129000000000000,0.213000000000000,0.162000000000000,0.0710000000000000,0.0250000000000000,0.0190000000000000;0.111000000000000,0.193000000000000,0.143000000000000,0.0610000000000000,0.0210000000000000,0.0180000000000000;0.0990000000000000,0.179000000000000,0.130000000000000,0.0550000000000000,0.0190000000000000,0.0170000000000000;0.0880000000000000,0.167000000000000,0.118000000000000,0.0490000000000000,0.0160000000000000,0.0160000000000000;0.0790000000000000,0.156000000000000,0.109000000000000,0.0450000000000000,0.0150000000000000,0.0150000000000000;0.0740000000000000,0.150000000000000,0.103000000000000,0.0420000000000000,0.0140000000000000,0.0150000000000000;0.0730000000000000,0.146000000000000,0.101000000000000,0.0410000000000000,0.0140000000000000,0.0150000000000000;0.0730000000000000,0.143000000000000,0.100000000000000,0.0410000000000000,0.0140000000000000,0.0140000000000000;0.0760000000000000,0.142000000000000,0.102000000000000,0.0430000000000000,0.0150000000000000,0.0150000000000000;0.0810000000000000,0.143000000000000,0.105000000000000,0.0450000000000000,0.0160000000000000,0.0160000000000000;0.0870000000000000,0.146000000000000,0.111000000000000,0.0480000000000000,0.0180000000000000,0.0170000000000000;0.0950000000000000,0.152000000000000,0.119000000000000,0.0520000000000000,0.0200000000000000,0.0180000000000000;0.106000000000000,0.160000000000000,0.130000000000000,0.0570000000000000,0.0220000000000000,0.0190000000000000;0.120000000000000,0.170000000000000,0.141000000000000,0.0630000000000000,0.0240000000000000,0.0200000000000000;0.131000000000000,0.178000000000000,0.152000000000000,0.0690000000000000,0.0270000000000000,0.0210000000000000;0.141000000000000,0.185000000000000,0.160000000000000,0.0740000000000000,0.0290000000000000,0.0230000000000000;0.149000000000000,0.192000000000000,0.168000000000000,0.0780000000000000,0.0300000000000000,0.0230000000000000;0.157000000000000,0.198000000000000,0.176000000000000,0.0820000000000000,0.0320000000000000,0.0240000000000000;0.167000000000000,0.206000000000000,0.185000000000000,0.0870000000000000,0.0340000000000000,0.0250000000000000;0.178000000000000,0.215000000000000,0.196000000000000,0.0920000000000000,0.0360000000000000,0.0260000000000000;0.193000000000000,0.227000000000000,0.211000000000000,0.100000000000000,0.0390000000000000,0.0280000000000000;0.216000000000000,0.246000000000000,0.232000000000000,0.111000000000000,0.0440000000000000,0.0300000000000000;0.240000000000000,0.265000000000000,0.255000000000000,0.123000000000000,0.0500000000000000,0.0330000000000000;0.262000000000000,0.284000000000000,0.277000000000000,0.134000000000000,0.0540000000000000,0.0350000000000000;0.286000000000000,0.304000000000000,0.300000000000000,0.145000000000000,0.0590000000000000,0.0370000000000000;0.309000000000000,0.324000000000000,0.322000000000000,0.156000000000000,0.0630000000000000,0.0400000000000000;0.330000000000000,0.343000000000000,0.343000000000000,0.167000000000000,0.0670000000000000,0.0420000000000000;0.352000000000000,0.362000000000000,0.364000000000000,0.178000000000000,0.0710000000000000,0.0440000000000000;0.374000000000000,0.382000000000000,0.385000000000000,0.188000000000000,0.0760000000000000,0.0460000000000000;0.397000000000000,0.402000000000000,0.408000000000000,0.200000000000000,0.0800000000000000,0.0480000000000000;0.421000000000000,0.424000000000000,0.431000000000000,0.211000000000000,0.0850000000000000,0.0500000000000000;0.444000000000000,0.445000000000000,0.454000000000000,0.223000000000000,0.0890000000000000,0.0530000000000000;0.469000000000000,0.468000000000000,0.479000000000000,0.236000000000000,0.0940000000000000,0.0560000000000000;0.498000000000000,0.495000000000000,0.508000000000000,0.251000000000000,0.100000000000000,0.0580000000000000;0.529000000000000,0.524000000000000,0.539000000000000,0.266000000000000,0.107000000000000,0.0620000000000000;0.561000000000000,0.554000000000000,0.571000000000000,0.282000000000000,0.113000000000000,0.0650000000000000;0.591000000000000,0.583000000000000,0.601000000000000,0.297000000000000,0.119000000000000,0.0680000000000000;0.619000000000000,0.610000000000000,0.631000000000000,0.311000000000000,0.125000000000000,0.0710000000000000;0.649000000000000,0.638000000000000,0.660000000000000,0.326000000000000,0.131000000000000,0.0740000000000000;0.677000000000000,0.665000000000000,0.688000000000000,0.340000000000000,0.136000000000000,0.0770000000000000;0.703000000000000,0.689000000000000,0.713000000000000,0.352000000000000,0.142000000000000,0.0800000000000000;0.726000000000000,0.711000000000000,0.736000000000000,0.364000000000000,0.146000000000000,0.0830000000000000;0.748000000000000,0.733000000000000,0.758000000000000,0.375000000000000,0.151000000000000,0.0850000000000000;0.772000000000000,0.755000000000000,0.781000000000000,0.387000000000000,0.155000000000000,0.0870000000000000;0.795000000000000,0.776000000000000,0.804000000000000,0.399000000000000,0.160000000000000,0.0900000000000000;0.816000000000000,0.797000000000000,0.824000000000000,0.409000000000000,0.164000000000000,0.0920000000000000;0.836000000000000,0.816000000000000,0.844000000000000,0.420000000000000,0.169000000000000,0.0940000000000000;0.857000000000000,0.836000000000000,0.864000000000000,0.431000000000000,0.173000000000000,0.0970000000000000;0.877000000000000,0.856000000000000,0.885000000000000,0.441000000000000,0.178000000000000,0.0980000000000000;0.897000000000000,0.875000000000000,0.905000000000000,0.451000000000000,0.182000000000000,0.101000000000000;0.914000000000000,0.892000000000000,0.924000000000000,0.460000000000000,0.186000000000000,0.103000000000000;0.929000000000000,0.907000000000000,0.940000000000000,0.468000000000000,0.190000000000000,0.105000000000000;0.942000000000000,0.921000000000000,0.954000000000000,0.476000000000000,0.193000000000000,0.106000000000000;0.953000000000000,0.932000000000000,0.966000000000000,0.482000000000000,0.195000000000000,0.108000000000000;0.963000000000000,0.941000000000000,0.975000000000000,0.487000000000000,0.197000000000000,0.109000000000000;0.971000000000000,0.949000000000000,0.984000000000000,0.491000000000000,0.199000000000000,0.110000000000000;0.978000000000000,0.956000000000000,0.991000000000000,0.496000000000000,0.201000000000000,0.112000000000000;0.983000000000000,0.962000000000000,0.998000000000000,0.500000000000000,0.203000000000000,0.112000000000000;0.990000000000000,0.966000000000000,1.00300000000000,0.504000000000000,0.204000000000000,0.113000000000000;0.996000000000000,0.972000000000000,1.00700000000000,0.508000000000000,0.207000000000000,0.114000000000000;1.00100000000000,0.978000000000000,1.01300000000000,0.511000000000000,0.209000000000000,0.115000000000000;1.00800000000000,0.984000000000000,1.02100000000000,0.516000000000000,0.211000000000000,0.117000000000000;1.01500000000000,0.994000000000000,1.02900000000000,0.521000000000000,0.213000000000000,0.117000000000000;1.02500000000000,1.00400000000000,1.04000000000000,0.527000000000000,0.216000000000000,0.118000000000000;1.03600000000000,1.01500000000000,1.05100000000000,0.534000000000000,0.218000000000000,0.119000000000000;1.04600000000000,1.02500000000000,1.06200000000000,0.539000000000000,0.221000000000000,0.121000000000000;1.05300000000000,1.03400000000000,1.07100000000000,0.544000000000000,0.223000000000000,0.121000000000000;1.06100000000000,1.03900000000000,1.07900000000000,0.548000000000000,0.224000000000000,0.122000000000000;1.06700000000000,1.04400000000000,1.08300000000000,0.551000000000000,0.225000000000000,0.122000000000000;1.06800000000000,1.04600000000000,1.08200000000000,0.552000000000000,0.225000000000000,0.122000000000000;1.06800000000000,1.04300000000000,1.07900000000000,0.551000000000000,0.225000000000000,0.122000000000000;1.06300000000000,1.03700000000000,1.07500000000000,0.549000000000000,0.224000000000000,0.122000000000000;1.05300000000000,1.02800000000000,1.06400000000000,0.545000000000000,0.223000000000000,0.121000000000000;1.04300000000000,1.01600000000000,1.05300000000000,0.540000000000000,0.221000000000000,0.121000000000000;1.02900000000000,1.00300000000000,1.03700000000000,0.532000000000000,0.218000000000000,0.119000000000000;1.01200000000000,0.987000000000000,1.01800000000000,0.523000000000000,0.214000000000000,0.118000000000000;0.990000000000000,0.967000000000000,0.996000000000000,0.511000000000000,0.210000000000000,0.115000000000000;0.966000000000000,0.944000000000000,0.973000000000000,0.498000000000000,0.204000000000000,0.112000000000000;0.940000000000000,0.919000000000000,0.949000000000000,0.484000000000000,0.198000000000000,0.109000000000000;0.914000000000000,0.893000000000000,0.922000000000000,0.470000000000000,0.191000000000000,0.106000000000000;0.884000000000000,0.865000000000000,0.893000000000000,0.454000000000000,0.185000000000000,0.103000000000000;0.853000000000000,0.834000000000000,0.863000000000000,0.437000000000000,0.178000000000000,0.100000000000000;0.820000000000000,0.804000000000000,0.833000000000000,0.420000000000000,0.171000000000000,0.0970000000000000;0.786000000000000,0.771000000000000,0.800000000000000,0.402000000000000,0.164000000000000,0.0930000000000000;0.750000000000000,0.734000000000000,0.763000000000000,0.383000000000000,0.157000000000000,0.0900000000000000;0.707000000000000,0.693000000000000,0.721000000000000,0.362000000000000,0.149000000000000,0.0860000000000000;0.664000000000000,0.651000000000000,0.677000000000000,0.339000000000000,0.140000000000000,0.0810000000000000;0.621000000000000,0.609000000000000,0.634000000000000,0.317000000000000,0.131000000000000,0.0760000000000000;0.579000000000000,0.569000000000000,0.591000000000000,0.295000000000000,0.123000000000000,0.0720000000000000;0.538000000000000,0.529000000000000,0.549000000000000,0.274000000000000,0.114000000000000,0.0670000000000000;0.498000000000000,0.491000000000000,0.507000000000000,0.254000000000000,0.106000000000000,0.0630000000000000;0.459000000000000,0.453000000000000,0.468000000000000,0.234000000000000,0.0980000000000000,0.0590000000000000;0.422000000000000,0.417000000000000,0.430000000000000,0.215000000000000,0.0900000000000000,0.0550000000000000;0.386000000000000,0.381000000000000,0.393000000000000,0.197000000000000,0.0830000000000000,0.0520000000000000;0.350000000000000,0.347000000000000,0.357000000000000,0.179000000000000,0.0760000000000000,0.0490000000000000;0.315000000000000,0.313000000000000,0.322000000000000,0.161000000000000,0.0690000000000000,0.0450000000000000;0.283000000000000,0.282000000000000,0.290000000000000,0.146000000000000,0.0620000000000000,0.0420000000000000;0.252000000000000,0.252000000000000,0.259000000000000,0.130000000000000,0.0560000000000000,0.0390000000000000;0.224000000000000,0.223000000000000,0.230000000000000,0.115000000000000,0.0500000000000000,0.0360000000000000;0.197000000000000,0.198000000000000,0.204000000000000,0.102000000000000,0.0440000000000000,0.0330000000000000;0.174000000000000,0.175000000000000,0.180000000000000,0.0900000000000000,0.0400000000000000,0.0310000000000000;0.153000000000000,0.155000000000000,0.159000000000000,0.0790000000000000,0.0350000000000000,0.0280000000000000;0.134000000000000,0.137000000000000,0.140000000000000,0.0690000000000000,0.0310000000000000,0.0260000000000000;0.117000000000000,0.119000000000000,0.122000000000000,0.0610000000000000,0.0270000000000000,0.0240000000000000;0.101000000000000,0.105000000000000,0.107000000000000,0.0520000000000000,0.0240000000000000,0.0220000000000000;0.0870000000000000,0.0910000000000000,0.0920000000000000,0.0450000000000000,0.0210000000000000,0.0210000000000000;0.0740000000000000,0.0780000000000000,0.0800000000000000,0.0390000000000000,0.0180000000000000,0.0200000000000000;];
standardConc=[500,500,500,250,100,50;]; %µM
X=standardAbs;
y=standardConc;
s=zeros(length(wv),1);
m=zeros(length(wv),1);
Rsquared=zeros(length(wv),1);
%Do linnear regression on standardspectra to get absorbance as a linnear
%function of concentration. linnear paramers s and m for every wavelength
%of the spectra are calculated. The predicted absorbance according to this
%model i then (concInExtract*s+m)+n
for i=1:length(standardAbs)
    [b,bint,r,rint,stats]=regress(X(i,:)',[ones(6,1), y']);
    s(i)=b(2);
    m(i)=b(1);
    Rsquared(i)=stats(1);
end

% The sample absorbance:
%119.2D 48h (positive control)
%x=[1.51500000000000;1.46200000000000;1.40400000000000;1.32700000000000;1.22400000000000;1.11500000000000;1.01800000000000;0.918000000000000;0.815000000000000;0.712000000000000;0.632000000000000;0.579000000000000;0.537000000000000;0.496000000000000;0.459000000000000;0.435000000000000;0.418000000000000;0.405000000000000;0.396000000000000;0.395000000000000;0.398000000000000;0.405000000000000;0.418000000000000;0.438000000000000;0.464000000000000;0.493000000000000;0.531000000000000;0.577000000000000;0.616000000000000;0.645000000000000;0.670000000000000;0.694000000000000;0.719000000000000;0.749000000000000;0.786000000000000;0.835000000000000;0.891000000000000;0.942000000000000;0.993000000000000;1.04200000000000;1.08500000000000;1.12500000000000;1.16400000000000;1.20300000000000;1.24100000000000;1.27700000000000;1.31200000000000;1.34800000000000;1.38900000000000;1.43300000000000;1.47100000000000;1.50800000000000;1.54200000000000;1.57500000000000;1.60600000000000;1.63100000000000;1.65200000000000;1.66900000000000;1.68500000000000;1.69200000000000;1.69500000000000;1.69800000000000;1.69200000000000;1.69000000000000;1.68900000000000;1.69100000000000;1.68700000000000;1.68600000000000;1.69000000000000;1.68600000000000;1.68400000000000;1.67700000000000;1.66500000000000;1.65200000000000;1.64500000000000;1.64000000000000;1.63200000000000;1.63100000000000;1.63300000000000;1.63700000000000;1.63600000000000;1.62800000000000;1.62700000000000;1.61800000000000;1.60900000000000;1.59100000000000;1.57500000000000;1.55300000000000;1.53000000000000;1.50300000000000;1.47800000000000;1.45400000000000;1.43300000000000;1.40600000000000;1.37200000000000;1.33600000000000;1.29600000000000;1.25400000000000;1.20500000000000;1.14500000000000;1.08000000000000;1.01600000000000;0.953000000000000;0.891000000000000;0.829000000000000;0.768000000000000;0.708000000000000;0.649000000000000;0.591000000000000;0.536000000000000;0.483000000000000;0.432000000000000;0.385000000000000;0.342000000000000;0.304000000000000;0.270000000000000;0.239000000000000;0.210000000000000;0.184000000000000;0.160000000000000;0.138000000000000;];
%pSB3K3-J23101-TAL 48h
%x=[1.04100000000000;0.989000000000000;0.934000000000000;0.870000000000000;0.790000000000000;0.711000000000000;0.645000000000000;0.585000000000000;0.530000000000000;0.476000000000000;0.436000000000000;0.409000000000000;0.390000000000000;0.372000000000000;0.358000000000000;0.350000000000000;0.345000000000000;0.341000000000000;0.341000000000000;0.344000000000000;0.350000000000000;0.358000000000000;0.370000000000000;0.387000000000000;0.407000000000000;0.429000000000000;0.456000000000000;0.488000000000000;0.515000000000000;0.534000000000000;0.551000000000000;0.568000000000000;0.585000000000000;0.605000000000000;0.630000000000000;0.663000000000000;0.698000000000000;0.730000000000000;0.761000000000000;0.790000000000000;0.816000000000000;0.839000000000000;0.862000000000000;0.885000000000000;0.907000000000000;0.929000000000000;0.950000000000000;0.972000000000000;0.996000000000000;1.01900000000000;1.03800000000000;1.05100000000000;1.06500000000000;1.07600000000000;1.08800000000000;1.10000000000000;1.10700000000000;1.11100000000000;1.11100000000000;1.10900000000000;1.10300000000000;1.09000000000000;1.07300000000000;1.05300000000000;1.03400000000000;1.01800000000000;1.00500000000000;0.995000000000000;0.987000000000000;0.979000000000000;0.970000000000000;0.961000000000000;0.950000000000000;0.940000000000000;0.929000000000000;0.919000000000000;0.909000000000000;0.898000000000000;0.888000000000000;0.878000000000000;0.867000000000000;0.857000000000000;0.845000000000000;0.833000000000000;0.820000000000000;0.804000000000000;0.788000000000000;0.771000000000000;0.754000000000000;0.734000000000000;0.713000000000000;0.691000000000000;0.669000000000000;0.647000000000000;0.624000000000000;0.600000000000000;0.576000000000000;0.553000000000000;0.527000000000000;0.499000000000000;0.469000000000000;0.441000000000000;0.412000000000000;0.385000000000000;0.359000000000000;0.333000000000000;0.308000000000000;0.285000000000000;0.261000000000000;0.238000000000000;0.217000000000000;0.197000000000000;0.178000000000000;0.161000000000000;0.145000000000000;0.131000000000000;0.119000000000000;0.107000000000000;0.0960000000000000;0.0860000000000000;0.0780000000000000;];
%pSB3K3-J23110-TAL 48h
%x=[0.977000000000000;0.918000000000000;0.858000000000000;0.789000000000000;0.705000000000000;0.625000000000000;0.563000000000000;0.511000000000000;0.465000000000000;0.425000000000000;0.396000000000000;0.378000000000000;0.366000000000000;0.357000000000000;0.351000000000000;0.349000000000000;0.349000000000000;0.351000000000000;0.355000000000000;0.362000000000000;0.370000000000000;0.379000000000000;0.394000000000000;0.414000000000000;0.436000000000000;0.460000000000000;0.490000000000000;0.525000000000000;0.553000000000000;0.574000000000000;0.592000000000000;0.610000000000000;0.627000000000000;0.648000000000000;0.674000000000000;0.707000000000000;0.744000000000000;0.775000000000000;0.806000000000000;0.833000000000000;0.857000000000000;0.878000000000000;0.899000000000000;0.919000000000000;0.939000000000000;0.957000000000000;0.974000000000000;0.992000000000000;1.01000000000000;1.02700000000000;1.03800000000000;1.04700000000000;1.05200000000000;1.05700000000000;1.06400000000000;1.06800000000000;1.07000000000000;1.06700000000000;1.05800000000000;1.04500000000000;1.02800000000000;1.00400000000000;0.974000000000000;0.944000000000000;0.915000000000000;0.889000000000000;0.868000000000000;0.850000000000000;0.835000000000000;0.819000000000000;0.804000000000000;0.787000000000000;0.768000000000000;0.749000000000000;0.729000000000000;0.708000000000000;0.686000000000000;0.663000000000000;0.640000000000000;0.617000000000000;0.596000000000000;0.576000000000000;0.556000000000000;0.538000000000000;0.520000000000000;0.502000000000000;0.482000000000000;0.465000000000000;0.448000000000000;0.432000000000000;0.415000000000000;0.398000000000000;0.382000000000000;0.368000000000000;0.353000000000000;0.339000000000000;0.325000000000000;0.311000000000000;0.296000000000000;0.280000000000000;0.264000000000000;0.248000000000000;0.232000000000000;0.216000000000000;0.201000000000000;0.187000000000000;0.173000000000000;0.160000000000000;0.147000000000000;0.134000000000000;0.122000000000000;0.111000000000000;0.101000000000000;0.0910000000000000;0.0830000000000000;0.0750000000000000;0.0690000000000000;0.0630000000000000;0.0570000000000000;0.0520000000000000;0.0470000000000000;];
%pSB3K3-CP8-TAL 48h
x=[1.16000000000000;1.10700000000000;1.04800000000000;0.980000000000000;0.891000000000000;0.804000000000000;0.730000000000000;0.660000000000000;0.592000000000000;0.526000000000000;0.476000000000000;0.443000000000000;0.418000000000000;0.396000000000000;0.377000000000000;0.365000000000000;0.357000000000000;0.352000000000000;0.350000000000000;0.353000000000000;0.359000000000000;0.367000000000000;0.381000000000000;0.400000000000000;0.424000000000000;0.450000000000000;0.481000000000000;0.519000000000000;0.552000000000000;0.575000000000000;0.596000000000000;0.615000000000000;0.635000000000000;0.658000000000000;0.688000000000000;0.727000000000000;0.770000000000000;0.807000000000000;0.845000000000000;0.881000000000000;0.912000000000000;0.940000000000000;0.968000000000000;0.997000000000000;1.02500000000000;1.05200000000000;1.07900000000000;1.10700000000000;1.13700000000000;1.16800000000000;1.19300000000000;1.21300000000000;1.22900000000000;1.24500000000000;1.26100000000000;1.27600000000000;1.29000000000000;1.29600000000000;1.30100000000000;1.30200000000000;1.29900000000000;1.28900000000000;1.27600000000000;1.25700000000000;1.24000000000000;1.22700000000000;1.21700000000000;1.20900000000000;1.20200000000000;1.19600000000000;1.18800000000000;1.17900000000000;1.17000000000000;1.16100000000000;1.15300000000000;1.14500000000000;1.14000000000000;1.13400000000000;1.12600000000000;1.11900000000000;1.11200000000000;1.10300000000000;1.09400000000000;1.08200000000000;1.06800000000000;1.05300000000000;1.03700000000000;1.01900000000000;0.999000000000000;0.976000000000000;0.950000000000000;0.922000000000000;0.893000000000000;0.865000000000000;0.835000000000000;0.802000000000000;0.770000000000000;0.738000000000000;0.703000000000000;0.664000000000000;0.624000000000000;0.584000000000000;0.545000000000000;0.508000000000000;0.473000000000000;0.437000000000000;0.404000000000000;0.371000000000000;0.338000000000000;0.306000000000000;0.277000000000000;0.249000000000000;0.223000000000000;0.198000000000000;0.177000000000000;0.158000000000000;0.140000000000000;0.124000000000000;0.110000000000000;0.0960000000000000;0.0840000000000000];
x=x*3/5; %Samples were concentrated 5 times in the extraction and diluted 3 times before measurement
%negative control:  119.2D 48h (negative control)
n=[0.708000000000000;0.659000000000000;0.609000000000000;0.554000000000000;0.486000000000000;0.424000000000000;0.379000000000000;0.344000000000000;0.318000000000000;0.298000000000000;0.285000000000000;0.279000000000000;0.276000000000000;0.277000000000000;0.281000000000000;0.286000000000000;0.291000000000000;0.296000000000000;0.304000000000000;0.313000000000000;0.321000000000000;0.330000000000000;0.343000000000000;0.361000000000000;0.380000000000000;0.399000000000000;0.423000000000000;0.451000000000000;0.474000000000000;0.489000000000000;0.503000000000000;0.515000000000000;0.527000000000000;0.542000000000000;0.558000000000000;0.578000000000000;0.599000000000000;0.617000000000000;0.633000000000000;0.646000000000000;0.657000000000000;0.665000000000000;0.672000000000000;0.678000000000000;0.683000000000000;0.687000000000000;0.690000000000000;0.692000000000000;0.694000000000000;0.694000000000000;0.691000000000000;0.682000000000000;0.672000000000000;0.662000000000000;0.656000000000000;0.649000000000000;0.639000000000000;0.623000000000000;0.601000000000000;0.579000000000000;0.554000000000000;0.522000000000000;0.487000000000000;0.453000000000000;0.420000000000000;0.392000000000000;0.369000000000000;0.350000000000000;0.332000000000000;0.314000000000000;0.297000000000000;0.279000000000000;0.259000000000000;0.239000000000000;0.220000000000000;0.201000000000000;0.182000000000000;0.164000000000000;0.147000000000000;0.132000000000000;0.120000000000000;0.108000000000000;0.0980000000000000;0.0890000000000000;0.0810000000000000;0.0730000000000000;0.0670000000000000;0.0610000000000000;0.0560000000000000;0.0520000000000000;0.0480000000000000;0.0450000000000000;0.0420000000000000;0.0400000000000000;0.0380000000000000;0.0370000000000000;0.0350000000000000;0.0340000000000000;0.0340000000000000;0.0330000000000000;0.0320000000000000;0.0310000000000000;0.0300000000000000;0.0290000000000000;0.0290000000000000;0.0280000000000000;0.0270000000000000;0.0270000000000000;0.0260000000000000;0.0250000000000000;0.0250000000000000;0.0240000000000000;0.0230000000000000;0.0230000000000000;0.0220000000000000;0.0220000000000000;0.0210000000000000;0.0210000000000000;0.0200000000000000;0.0200000000000000;0.0200000000000000;];
n=n*3/5; %Samples were concentrated 5 times in the extraction and diluted 3 times before measurement
% Calculating concInExtract in an ordinary least squares manner
concInExtract =(((x-n-m)')*s)/(s'*s) % concentration in extract [µM] so that norm(x-((concInExtract*s+m)+n)) is minimized. The bestfit between experimentel data (x) and absorbance acocrding to the model ((concInExtract*s+m)+n) is found by minimizing this norm.   
yield=425.7428/500; %(concInCulture/concInExtract) for positive control (concInCulture known before extraction)
concInCulture = concInExtract/yield % concentration in culture 

%Calculating the norm that is minimized by the script (for visualisation)
plotint=-100:1000;
J=zeros(length(plotint),1);
i=1;
for k=plotint
   
    J(i)=(x-n-k*s-m)'*(x-n-k*s-m);
    i=i+1;
end

%Plotting the norm that is minimized by the script as a function of
%concInExtract
figure();
plot(plotint,J);
title('Norm as a function of concInExtract')
ylabel('||experimental absorbance - absorbance(concInExtract)||');
xlabel('concInExtract [µM]');

%Plotting how well the experimental absorbance fits with the absorbance
%according to the model with the opimized concInExtract
figure();
plot(wv,x);
hold;
plot(wv,n+concInExtract*s+m,'g');
title('Fit beetwen experimental absorbance and absorbance according to model with optimized concInExtract')
xlabel('wavelength [nm]');
ylabel('mAU');
legend('Location','SouthOutside','experimental absorbance',strcat('absorbance according to model with concInExtract = ',num2str(concInExtract),' µM'));