using fit function,Error using fittype>iDeduceCoefficients
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How do I get a string properly input into a fit function?
I'm trying to fit the wave equation to find the amp and phase for each row of 'zs'-x and 'data'-y (both 401x20). I have input a string that will vary with the changing frequency ('wn', 401x1) for each row of 'zs'. I get the following error:
---------------------------------------------------------------
Error using fittype>iDeduceCoefficients (line 621)
The independent variable x does not appear in the equation expression.
Use x in the expression or indicate another variable as the independent variable.
Error in fittype>iCreateCustomFittype (line 477)
obj = iDeduceCoefficients(obj);
Error in fittype>iCreateFittype (line 353)
obj = iCreateCustomFittype( obj, varargin{:} );
Error in fittype (line 330)
obj = iCreateFittype( obj, varargin{:} );
Error in fit>iFit (line 165)
model = fittype( fittypeobj, 'numindep', size( xdatain, 2 ) );
Error in fit (line 116)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in z_fit (line 11)
ft = fit(z1(:), ampRow(:), 'a * sin(',num2str(wn),' * x + c)', 'StartPoint', [5, 0], 'Lower',[0,-Inf],
'Upper',[Inf,Inf]);
------------------------------------------
Below is the code:
n = length(zs);
for i = 1:n
ampRow = data(i,:);
z1 = zs(i,:);
wn = 2.*pi.*Freq(:)./299.79;
ft = fit(z1(:), ampRow(:), 'a * sin(',num2str(wn),' * x + c)', 'StartPoint', [5, 0], 'Lower',[0,-Inf], 'Upper',[Inf,Inf]);
vals = coeffvalues(ft);
ampFixedFreq_nd(i) = vals(1);
phaseFixedFreq_nd(i) = vals(2);
end
Respuestas (1)
Steven Lord
el 24 de Sept. de 2019
Rather than building the equation using the text form of your problem parameter, I recommend creating a fittype with a 'problem' parameter and specifying a value for that 'problem' parameter when you call fit. See the "Create Fit Options and Fit Type Before Fitting" example on the documentation page for the fit function for an illustration of this technique. The n parameter from the example fills the same role as the wn parameter in your equation.
0 comentarios
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!