필터 지우기
필터 지우기

fit data trend with equation

조회 수: 1 (최근 30일)
C.G.
C.G. 2022년 8월 1일
답변: Milan Bansal 2023년 9월 20일
I have the datset attached, and i'm trying to find an equation which describes the trend.
I have tried using basic fitting but it does not fit a line and comes up with NaN's. Is there a reason for this and how can I find a trend easily?
load smd_period.mat
plot(period,smd,'-k')
xlim([0 5000])
xlabel('Period (s)')
ylabel('Power-Power')

답변 (1개)

Milan Bansal
Milan Bansal 2023년 9월 20일
Hi,
I understand that you are facing an issue while fitting a curve to the given data.
As per the given data, output of the fitting function is "NaN" because the "period" variable in the attached ".mat" file contains repetitive values. Define the "period" variable using "linspace" function as shown in the example below.
period = linspace(0,5000,16385);
Use "polyfit" function to fit an approximate "n" degree polynomial to the data.
p = polyfit(period,smd,50); % fitting a 50 degree polynomial
Refer to the following documentation to learn more about "polyfit" function.
Obtain the fitted curve using "polyval" function.
y = polyval(p,period);
Refer to the following documentation to learn more about "polyval" function.
Hope it helps!

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by