Fitting Polynomial Curve for 4,000 curves.
古いコメントを表示
I would like to fit a second order polynomial where data(1:7,1) is the x and data(1:7,i) is the y. I would like to loop through where i=2,3,4,5, and so on. I have 4,000 i in my actual data set. Any help would be great.

4 件のコメント
dpb
2016 年 2 月 4 日
What if it were only two? Would you still be stuck?
John D'Errico
2016 年 2 月 4 日
Hint:
help for
todd feldman
2016 年 2 月 4 日
dpb
2016 年 2 月 4 日
Question was whether you've conceptually having a problem with how to do anything multiple times or just overwhelmed by the numbers...
回答 (2 件)
ord = 2;
data = [1:7;20:23,25,26,25;21,24,23,23:26]'
num = size(data,2)-1;
cof = cell(ord+1,1);
for k = 1:num
cof{k} = polyfit(data(:,1),data(:,1+k),ord);
end
then to get the coefficients in a numeric array:
mat = cell2mat(cof);
Same basic solution as Stephen's above excepting doing the conversion on the front end instead of the latter and having implicit loop instead of explicit...
[nr nc]=size(data); % rows, columns in data
y=mat2cell(data(:,2:end),nr,ones(nc-1,1)); % convert to a cell array by column
poly=2; % order to fit
coeff=cellfun(@(y,poly) polyfit(data(:,1),y,poly),y, ...
'uniformoutput',false); % compute
As Stephen showed, can then convert to an "ordinary" 2D array with cell2mat or leave as cell array. If choose to convert, can simply wrap that around the cellfun call and do it all in "one swell foop".
coeff=cell2mat(cellfun(@(y,poly) polyfit(data(:,1),y,poly),y, ...
'uniformoutput',false));
カテゴリ
ヘルプ センター および File Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!