Using polyfit in two arrays to detrend data.

8 ビュー (過去 30 日間)
Fabian
Fabian 2023 年 6 月 13 日
コメント済み: Fabian 2023 年 6 月 16 日
I have two 5x1 arrays (x and y oth come from one data table) and need to use them to detrend a data set. My line of code to do so is below. I keep getting the error of "arrays have incompatible array sizes for this operation." My question is, what can I do to make the array sizes work with the polyfit?
data_detrend = data-polyfit(x,y,4)

採用された回答

Matt J
Matt J 2023 年 6 月 14 日
編集済み: Matt J 2023 年 6 月 14 日
p=polyfit(x,y,4);
data_detrend = y-polyval(p,x)
  1 件のコメント
Fabian
Fabian 2023 年 6 月 16 日
Thank you so much this worked!

サインインしてコメントする。

その他の回答 (1 件)

Alan Stevens
Alan Stevens 2023 年 6 月 13 日
編集済み: Alan Stevens 2023 年 6 月 13 日
polyfit just returns the coefficients of the polynomial. You need to use them in polyval to calculate data values.
  1 件のコメント
Fabian
Fabian 2023 年 6 月 13 日
I tried polyval but the same issue comes up regarding the arrays not having compatible sizes

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by