Using polyfit in two arrays to detrend data.

조회 수: 4 (최근 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개)

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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by