how to smooth scatter plots like excel?
10 views (last 30 days)
Show older comments
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?
2 Comments
Answers (1)
Image Analyst
on 29 Apr 2013
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)
0 Comments
See Also
Categories
Find more on Smoothing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!