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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Shadi
on 29 Apr 2013

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.*

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)

## 2 Comments

## omid jab (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/73917#comment_146034

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

## Zhang lu (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/73917#comment_146036

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