Using polyfit in two arrays to detrend data.

4 visualizaciones (últimos 30 días)
Fabian
Fabian el 13 de Jun. de 2023
Comentada: Fabian el 16 de Jun. de 2023
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)

Respuesta aceptada

Matt J
Matt J el 14 de Jun. de 2023
Editada: Matt J el 14 de Jun. de 2023
p=polyfit(x,y,4);
data_detrend = y-polyval(p,x)

Más respuestas (1)

Alan Stevens
Alan Stevens el 13 de Jun. de 2023
Editada: Alan Stevens el 13 de Jun. de 2023
polyfit just returns the coefficients of the polynomial. You need to use them in polyval to calculate data values.
  1 comentario
Fabian
Fabian el 13 de Jun. de 2023
I tried polyval but the same issue comes up regarding the arrays not having compatible sizes

Iniciar sesión para comentar.

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by