多次元配列に対するPolyfitの高速化

6 views (last 30 days)
Kouta Amano
Kouta Amano on 3 Sep 2019
Commented: Kouta Amano on 4 Sep 2019
私は測定水準x, 測定値yに対し y=a0 + a1*x + a2*x^2 の形でカーブフィッティングを行いたいと考えています。
例えばxの次元は100万×3, yの次元は100万×3であり、1行1行について上記カーブフィッティングを行いたいです。
arrayfunを用いて下記のような関数を作成すると計算は可能でしたが実行速度が大変遅いです。
実行速度を改善するために、よりよい実装方法はないでしょうか。
function coefs = multiPolyfit(x,y,dim)
%%%%%%%%%%%%%%%%%%%%%%%
% x: array型。サンプルを行方向、列方向は水準。
% y: array型。サンプルを行方向、列方向は水準。
% dim: int型
%%%%%%%%%%%%%%%%%%%%%%%
s = table2struct(table(x,y,'VariableNames',{'x','y'}));
coefs = arrayfun(@(z) polyfit(z.x,z.y,dim),s,'UniformOutput',false);
end

Accepted Answer

Kazuya
Kazuya on 4 Sep 2019
こちらに同じ質問が見つかりました。Matt Tearle さんの回答で10倍くらいは速くなりそうです。
  1 Comment
Kouta Amano
Kouta Amano on 4 Sep 2019
ありがとうございます。
自分のもとの実装に比べて50倍速くなりました・・・。

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!