I'd like to plot a set of simple data with a 'smooth curve' just as excel does. I can use matlab's "scatter(x,y)' feature but I'd like to have the data points connected. Can anyone help?
No products are associated with this question.
You could try splines, like in my demo:
% Demo to show spline interpolation. % clc; close all; clear all; workspace; % Display workspace panel.
% Plot the original points. x = 1:10; y = rand (10,1); % Plot it and show how the line has sharp bends. plot(x, y, '-sr', 'LineWidth', 2); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Use splines to interpolate a smoother curve % that goes exactly through the same data points. samplingRateIncrease = 10; newXSamplePoints = linspace(1, 10, 10 * samplingRateIncrease); smoothedY = spline(x, y, newXSamplePoints); hold on; % Don't destroy the first curve we plotted. % Plot smoothedY and show how the line is % smooth and has no sharp bends. plot(newXSamplePoints, smoothedY, '-ob'); title('Spline Interpolation Demo', 'FontSize', 20);
legend('Original Points', 'Spline Points');
% Mathworks Demo code from their Help % x = 0:10; % y = sin(x); % xx = 0:.25:10; % yy = spline(x,y,xx); % plot(x,y,'o',xx,yy)
Play games and win prizes!Learn more