Cool, I've tried a few ways and am happy I'm finally one step closer. The code works perfectly, but only for the first 12 events. At event 13 it gives me an error:
"Index exceeds the number of array elements"
And I can't figure out why. I suspect the problem is marked with (*) , but do not know how to solve it.
smtmp = smcellere(:);
for i = 1:length(smtmp)
sm = smtmp{i,:}.';
t = 1:length(sm);
SMF = (1:0.1:SMO(i));
good = sm(~isnan(sm)).';
figure, plot(t,sm,'--ob');
hold on
for ai = 1:length(SMF)
for aii = 1:length(tau)
SM = (SMO(i)-SMF(ai))*exp(-t./tau(aii))+SMF(ai);
% **rmse(ai,aii) = sqrt(sum((SM-sm).^2)/length(sm));**
end
end
[aai,aaj] = find(rmse == min(rmse(:)));
% if aai > length(SMF)
% smf=SMF(length(SMF));tau2 = tau(aaj);
% elseif aai < length(SMF)
smf=SMF(aai);tau2 = tau(aaj);
% end
smcalc = (SMO(i)-smf)*exp(-t./tau2)+smf;
plot(t,smcalc,'-or');
hold off
end
Any input is much appreciated.