fid = fopen('gc-data-21.txt', 'r');
data = textscan(fid, '%f %s %f');
readfile=@(fn)cellstr(readlines(fn));
npoints = length(ind);
Unrecognized function or variable 'ind'.
time = zeros(npoints, 1);
signal = zeros(npoints, 1);
time(i) = data{1}(ind(i));
signal(i) = data{2}(ind(i));
signal = signal - mean(signal);
gauss = @(p, x) p(1)*exp(-((x - p(2))./p(3)).^2) + p(4);
obj = @(p) sum((gauss(p, time) - signal).^2);
p0 = [1, mean(time), std(time), 0];
gauss2 = @(p, x) p(1)*exp(-((x - p(2))./p(3)).^2) + p(4) + p(5)*exp(-((x - p(6))./p(7)).^2) + p(8);
p0 = [1, mean(time), std(time), 0, 1, mean(time), std(time), 0];
plot(time, gauss2(p0, time))
title('fitting function with initial guess')
p2 = lsqnonlin(obj2, p0);
plot(time, gauss2(p2, time))
peak1 = gauss(p2(1:4), time);
peak2 = gauss(p2(5:8), time);
legend('Peak 1', 'Peak 2')
title('the two extracted peaks')
area1 = trapz(time, peak1);
area2 = trapz(time, peak2);
fprintf('Integrated area 1: %f\n', area1)
fprintf('Integrated area 2: %f\n', area2)
rel1 = area1/(area1 + area2);
rel2 = area2/(area1 + area2);
fprintf('Relative amount 1: %f\n', rel1)
fprintf('Relative amount 2: %f\n', rel2)