MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

how to smooth scatter plots like excel?

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?

omid jab on 29 Apr 2013

It's not posible using "scatter". you could test another.

Zhang lu on 29 Apr 2013

do you mean 'plot(x,y,'-*')' ?

Products

No products are associated with this question.

Answer by 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)
```