use polyfit to plot a fot for data in matlab

main.m
% Assuming you have the x and y data
x = [1, 2, 3, 4, 5];
y = [2, 3, 5, 6, 5];

% Specifying the degree of the polynomial fit
degree = 2;

% Performing the polynomial fit
coefficients = polyfit(x, y, degree);

% Creating a range of x values for plotting
xRange = 1:0.1:5;
yFit = polyval(coefficients, xRange);

% Plotting the original data points and the fitted polynomial curve
plot(x, y, 'o', xRange, yFit);
legend('Data', 'Fitted curve');
442 chars
18 lines

gistlibby LogSnag