필터 지우기
필터 지우기

how to fit the curve and delete the original data point and save the fitted curve

조회 수: 7 (최근 30일)
Hello Everyone,
I have few data sets and want to fit the curve, so that my curves will look smooth.
I am sharing the code here, would you please guide me;
p_pro_100_=[
5.8045
5.2853
5.0573
4.4518
3.1702
1.7467 ];
p_pro_4_=[
6.1060
4.5033
5.4187
4.8306
4.5205
4.0070
3.4725
];
p_pro_50um_ =[6.0051
4.4763
4.1868
2.0373
];
cy_50 = [4 300 400 450]';
cy = [4 100 200 300 400 500 600]';
cy_100 =[4 100 200 300 350 370]';
figure
hold on
ax = gca;
ax.XTick = 100:100:600;
plot(cy,p_pro_4,'-o',LineWidth= 4)
plot(cy_50,p_pro_50um,'-*',LineWidth= 4)
plot(cy_100,p_pro_100,'-^',LineWidth= 4)
legend ('20','50','100')

채택된 답변

Atithi
Atithi 2023년 7월 6일
To fit a smooth curve to your data sets, you can use interpolation or curve fitting techniques. One common approach is to use the interp1 function in MATLAB/Octave, which performs linear interpolation by default. Here's an example of how you can modify your code to include curve fitting:
In this code, the interp1 function is used to interpolate the data points onto a finer grid (cy_fit) using spline interpolation. The resulting interpolated data is then plotted to obtain smooth curves. Feel free to adjust the interpolation method or the number of points in the cy_fit grid to suit your needs.
p_pro_100_ = [5.8045; 5.2853; 5.0573; 4.4518; 3.1702; 1.7467];
p_pro_4_ = [6.1060; 4.5033; 5.4187; 4.8306; 4.5205; 4.0070; 3.4725];
p_pro_50um_ = [6.0051; 4.4763; 4.1868; 2.0373];
cy_50 = [4 300 400 450]';
cy = [4 100 200 300 400 500 600]';
cy_100 = [4 100 200 300 350 370]';
% Perform curve fitting
cy_fit = linspace(min(cy), max(cy), 1000); % Generate a finer grid for smooth curve
p_pro_4_fit = interp1(cy, p_pro_4_, cy_fit, 'spline');
p_pro_50um_fit = interp1(cy_50, p_pro_50um_, cy_fit, 'spline');
p_pro_100_fit = interp1(cy_100, p_pro_100_, cy_fit, 'spline');
figure
hold on
ax = gca;
ax.XTick = 100:100:600;
plot(cy_fit, p_pro_4_fit, '-o', 'LineWidth', 0.2)
plot(cy_fit, p_pro_50um_fit, '-*', 'LineWidth', 1)
plot(cy_fit, p_pro_100_fit, '-^', 'LineWidth', 1)
legend('20', '50', '100')
Do let me know if it helps.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Smoothing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by