hello i want to loop this function, anyone can help me? thank you
1 view (last 30 days)
Show older comments
mdl1 = fitlm(Xtr1,Ytr1,'quadratic');
mdl2 = fitlm(Xtr2,Ytr2,'quadratic');
mdl3 = fitlm(Xtr3,Ytr3,'quadratic');
mdl4 = fitlm(Xtr4,Ytr4,'quadratic');
mdl5 = fitlm(Xtr5,Ytr5,'quadratic');
mdl6 = fitlm(Xtr6,Ytr6,'quadratic');
1 Comment
dpb
on 29 Jan 2023
Turn the
X
,
Y
variables into arrays and then pass to the function by column indices in the loop; save the result as cell array.
Accepted Answer
Luca Ferro
on 30 Jan 2023
Xtr=[Xtr1 Xtr2 Xtr3 Xtr4 Xtr5 Xtr6];
Ytr=[Ytr1 Ytr2 Ytr3 Ytr4 Ytr5 Ytr6];
mdl=[];
forjj=1:lenght(Xtr)
mdl (jj) = fitlm (Xtr (jj) Ytr (jj),'quadratic')
end
as said by dpb in the comments.
2 Comments
Luca Ferro
on 31 Jan 2023
oh yeah i'm desolated, didn't check neither knew that ftilm was a matlab function, i thought it was custom made.
I also didn't know about how length has this huge critical aspect, thank you for educating me about it :)
More Answers (0)
See Also
Categories
Find more onLoops and Conditional StatementsinHelp CenterandFile Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!