How can I use a 'for loop' with the 'for' variable inside a string?

I am trying to do a 'for loop' of a nonlinear fit where one of the coefficients of the fit model changes with each loop. The coefficients are in a 29x1 double called 'YoungMod'. So what I want in the end is the fit coefficients (E1 and b) for each loop with a different value of 'YoungMod'. This is what I currently have:
for k=1:size(DataAll,3)
ft{k} = fittype('1.21.*(1500.*(1./(YoungMod(k+2))+1./(E1.*(1-exp(-1)))).*(1-exp(-...(t./90).^b)).*cotd(65.35)).^0.5','independent', 't','dependent','depth','options',fo);
[FittedData{k},gof{k}] = fit(DataAll(:,3,k),DataAll(:,1,k),ft{k});
coeffs{k}=coeffvalues(FittedData{k});
end
The error message I receive is:
Error using fittype>iTestCustomModelEvaluation (line 726)
Expression
1.21.*(1500.*(1./(YoungMod(k+2))+1./(E1.*(1-exp(-1)))).*(1-exp(-(t./90).^b)).*cotd(65.35)).^0.5
is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated:
Error in fittype expression ==>
1.21.*(1500.*(1./(YoungMod(k+2))+1./(E1.*(1-exp(-1)))).*(1-exp(-(t./90).^b)).*cotd(65.35)).^0.5
??? Undefined function 'YoungMod' for input arguments of type 'double'.
Error in fittype>iCreateFittype (line 367)
iTestCustomModelEvaluation( obj );
Error in fittype (line 324)
obj = iCreateFittype( obj, varargin{:} );
Error in automated_main (line 90)
ft{k} =
fittype('1.21.*(1500.*(1./(YoungMod(k+2))+1./(E1.*(1-exp(-1)))).*(1-exp(-(t./90).^b)).*cotd(65.35)).^0.5','independent',
't','dependent','depth','options',fo);
Caused by:
Error using fittype/evaluate (line 102)
Error in fittype expression ==>
1.21.*(1500.*(1./(YoungMod(k+2))+1./(E1.*(1-exp(-1)))).*(1-exp(-(t./90).^b)).*cotd(65.35)).^0.5
??? Undefined function 'YoungMod' for input arguments of type 'double'.
I believe the the problem is that the loop variable is in a string but I cannot figure out how to solve it.

Categories

Products

Asked:

on 16 Jan 2014

Answered:

on 16 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!