I want to use polyfit in a NxM matrix rather than a for loop
11 views (last 30 days)
Show older comments
How can I do this in one line of code? For Loops Take too long.
for i=1:2^(9)
polydata_Run1 = polyfit((1:2^(11))',SEG_RUN1(:,i),1);
Best_Fit_(:,i) = polyval(polydata_Run1,(1:2^(11)));
end
0 Comments
Accepted Answer
Matt J
on 8 Nov 2013
Edited: Matt J
on 8 Nov 2013
A=[linspace(0,1,2^11);ones(1,2^11)].';
[Q,R]=qr(A,0);
Best_Fit_ = A*(R\(Q'*SEG_RUN1));
More Answers (0)
See Also
Categories
Find more on Linear Algebra 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!