By default, MATLAB's plot function generates piecewise linear segments. To create a smoother curve, interpolation between discrete data points can help. MATLAB offers several interpolation methods:
- PCHIP/Cubic: Shape-preserving piecewise cubic (smooth, maintains monotonicity)
- Spline: Cubic spline interpolation (smooth but may overshoot)
- Makima: Modified Akima cubic interpolation (balances smoothness and shape)
Here's an example using PCHIP interpolation to generate a smooth curve alongside the original data:
% Original data (time in seconds, mass in kg)
x = [0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700];
y = [0.008, 0.007, 0.006, 0.004, 0.003, 0.002, 0.001, 0.001, 0.001, 0.001];
% Create fine grid for smooth interpolation
x_fine = linspace(0, 2700, 1000); % 1000 points between 0-2700 seconds
y_fine = interp1(x, y, x_fine, 'pchip'); % Cubic interpolation
% Plot settings
plot(x_fine, y_fine, 'b-', 'LineWidth', 1.5); % Smooth blue curve
hold on;
plot(x, y, ':r', 'LineWidth', 1.5); % Piecewise linear curve
grid on;
% Axis and labels
axis([0, 3000, 0, 0.009]); % Extend x-axis to 3000 seconds
title('Mass-Time Evaporation Analysis');
xlabel('Time of evaporation (seconds)');
ylabel('Mass of blood evaporated (kg)');
legend('Interpolated Curve', 'Default Curve', 'Location', 'best');
hold off;
The interpolation creates 1000 refined points between measurements, generating a continuous curve while preserving the data's original shape.
For more interpolation options, explore the documentation:
doc interp1