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

5 次查看(过去 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 中查找有关 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