How do I write coefficients from nonlinear fits to an array from a loop statement?
1 次查看(过去 30 天)
显示 更早的评论
So I am trying to write the coefficients from nonlinear fits I'm doing to an array, but the loop function is writing over the values so I wind up with only the coefficients from the last fit. This is a portion of my code so far.
for Replicate_Loop = 1:Num_Days
Model = char(Equations(Model_Loop,1));
ft_NoZeros = fittype(Model,'independent', 'x', 'dependent', 'y' );
[fitresult_NoZeros, gof_NoZeros] = fit( xData_NoZeros, yData_NoZeros, ft_NoZeros, opts);
values=coeffvalues(fitresult_NoZeros);
end
I'm fairly new to Matlab, so I'm getting a bit lost when it comes to writing the values for each fit including nesting other for loops in, but I don't know the syntax very well. Any help would be really appreciated! Thank you!
0 个评论
采纳的回答
Star Strider
2017-6-1
I would save the results to cell arrays for each output you want to save.
Example —
for Replicate_Loop = 1:Num_Days
Model = char(Equations(Model_Loop,1));
ft_NoZeros = fittype(Model,'independent', 'x', 'dependent', 'y' );
[fitresult_NoZeros{Replicate_Loop}, gof_NoZeros{Replicate_Loop}] = fit( xData_NoZeros, yData_NoZeros, ft_NoZeros, opts);
values{Replicate_Loop}=coeffvalues(fitresult_NoZeros{Replicate_Loop});
end
Note: The curly braces ‘{}’ denote cell array indexing. See the documentation on Cell Arrays (link) for a full description of them and how to use them.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!