The graph basic fitting tool accepts a matrice but not the polyfit function... How to do the same thing in a script ?
Show older comments
I made a graph of the evolution of a variable through 10 time periods (colums) for 10 individuals (lines). The graph basic fitting gives a nice fourth degree fit which I want to reproduce in a script for different variables. I tried with polyfit but it doe not take a matrice as input. Could somebody tell me how to replicate the treatment of the basic fittiing tool in a script ? Here is the graph and the data in DATA.mat attached file.
Thanks alot for any help.

Accepted Answer
More Answers (1)
Antoni Garcia-Herreros
on 27 Mar 2023
Hello,
Something like this might do the trick:
close all
for i=1:10; % Loop through your variables
p=polyfit([1:10]',vcz(:,i)',4);
YT=polyval(p,T);
p1=plot([1:10],vcz(:,i));
L=legend;
hold on
p2=plot(T,YT,'LineWidth',2);
L.String{end}=['Fitted ' L.String{end-1}];
end
Hope this helps!
1 Comment
Jacques Larue
on 27 Mar 2023
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!