- Try spline(). See attached example.

- Did you try interp1?

10 views (last 30 days)

I have a few questions which are:

1: I have plotted 13 x-values and 13 y-values, but I want this curve to be smooth and want

more values in between each point to make it smoother.

2: From this picture above, we want to find the y values from known x-values, but in this case different x-values.

Image Analyst
on 4 Nov 2020

- Try spline(). See attached example.

% Demo to show spline interpolation.

% Clean up / initialize

clc;

close all;

clear all;

workspace; % Display workspace panel.

% Create the original knot points.

lengthX = 10;

x = 1:lengthX;

y = rand (lengthX,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,

% with 10 times as many points,

% that goes exactly through the same data points.

samplingRateIncrease = 10;

newXSamplePoints = linspace(1, max(x), lengthX * samplingRateIncrease);

smoothedY = spline(x, y, newXSamplePoints);

% Plot smoothedY and show how the line is

% smooth, and has no sharp bends.

hold on; % Don't destroy the first curve we plotted.

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)

slopes = [0, diff(smoothedY)];

plot(newXSamplePoints, slopes, 'k-', 'LineWidth', 3);

% Draw x axis

line(xlim, [0,0], 'Color', 'k', 'LineWidth', 2);

grid on;

legend('Original Points', 'Spline Points', 'Slope');

- Did you try interp1?

xEstimated = interp1(x, y, xSpecified)

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 2 Comments

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/636480-matlab-table-find-y-values-from-x-values#comment_1110230

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/636480-matlab-table-find-y-values-from-x-values#comment_1110230

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/636480-matlab-table-find-y-values-from-x-values#comment_1117090

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/636480-matlab-table-find-y-values-from-x-values#comment_1117090

Sign in to comment.