Yes. If you have more than one independent variable, concatenate all of them in a matrix (I prefer they be column vectors), then refer to them by their columns within the model function you want to fit.
For instance, if you want to fit: y = a*x1^2 + b*exp(c*x2), create your ‘x1x2’ matrix (or whatever you want to call it) as:
then in the function you want to use to fit your data, using a single vector ‘b’ for your parameter vector:
f = @(b,x) b(1).*x1x2(:,1).^2 + b(2).*exp(b(3).*x1x2(:,2));
and the call to nlinfit (for example) would then be:
B = nlinfit(x1x2, y, f, B0);
That is how I do it, and it works. You would simply expand what I call ‘x1x2’ here to include your four independent variable value vectors.
(Note: all the code here is untested, but then it’s also all hypothetical.)
Best Answer