MATLAB: How to pass a fitting parameter such that it can only take on certain values

curve fittingCurve Fitting ToolboxfitMATLAB

If I want to pass constants from my workspace as parameters in a funciton to fit data with using Matlab's fit() function, I can do something like this:
phi1 = somevalue1;
phi2 = somevalue2;
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0,0],...
'Upper',[1,1,2*pi],...
'StartPoint',[.5,.5,0]);
ft = fittype('A*abs(cos(x-phi1) + B*cos(x-phi2)*exp(1i*gamma))^2','problem',{'phi1','phi2'},'options',fo);
[fit_parameters,fit_error] = fit(rad,I,ft,'problem',{phi1,phi2});
Where phi1 and phi2 are constants being passed to the fit function to then find A, B, and gamma through fitting.
I instead want to be able to fit using two different values of phi1, for example corresponding to the cosine functions being in or out of phase. Therefore, I wan't to be able to do something like:
phi1 = [somevalue1,somevalue1+pi/2]
phi2 = somevalue2;
and try fitting with parameters A, B and gamma using both values of phi1.
Any thoughts here? Thanks

Best Answer

Repeat the fit in a loop over the small number of combinations of discrete values that phi and phi2 can assume. Then take the result which gives the lowest fitting error.