MATLAB: Fit surface to data set

cftoolfamefitMATLABsurface

So, I've got this data set with 3 vars (attached), time, temperature and percentage conversion. It's from a FAMEs chemical reaction, and i've been using fruitessly cftool, to get a surface function that fits to data. Any suggestions on how to do this?
The aim is to predict percentage conversion by setting temp and time based on experimental data 😀
Thanks!

Best Answer

I don’t have the Curve Fitting Toolbox, but using the Statistics Toolbox function nlinfit or Optimization Toolbox function lsqcurvefit, it would be relatively easy. Assuming time and temperature are your independent variables, and percentageconversion your dependent variable, combine the first two in one matrix and then regress it against the third using your function.
Example:
TimeTemp = [time temperature]; % Assumes time and temperature are COLUMN vectors
FAMEfcn = (b,X) b(1).*X(:1) + b(2) .* X(:,2); % FAME = K1*time + K2*temperature
B = nlinfit(TimeTemp, percentageconversion, FAMEfcn, [1 1])
Obviously you would provide the function to fit. I created the very simple example FAMEfcn to illustrate how to refer to the TimeTemp variables within it. The percentageconversion vector is also assumed to be a column vector here.