Uniform point interpolation along a line described by non-uniform distributed points

3 views (last 30 days)
Hi everyone,
I would like to have uniformly distributed points along a line. The line in question is being described by non-uniform points. Does any of you know about any function to do so?
Thank you in advance for the help!
Álvaro

Accepted Answer

Image Analyst
Image Analyst on 5 Aug 2018
See this demo:
% Code to plot data, plus points interpolated in between the data.
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
% Make up sample data.
numOriginalPoints = 20;
xOriginal = sort(100 * rand(1, numOriginalPoints), 'ascend');
yOriginal = 30 * rand(1, numOriginalPoints) - 10;
% Plot them
subplot(3, 1, 1);
plot(xOriginal, yOriginal, 'ro-', 'LineWidth', 2);
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Training Points', 'FontSize', fontSize);
% Interpolate points in between, linearly from the min to the max.
numNewPoints = 100;
xInterpolated = linspace(min(xOriginal), max(xOriginal), numNewPoints);
yInterpolated = interp1(xOriginal, yOriginal, xInterpolated);
% Plot interpolated points.
subplot(3, 1, 2);
plot(xInterpolated, yInterpolated, 'bo-', 'LineWidth', 2);
% Plot training points over them so we can see where they are in relation to the new points.
hold on;
plot(xOriginal, yOriginal, 'ro', 'LineWidth', 2);
grid on;
title('Interpolated Points without Including Training Points', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
legend('Interpolated', 'Training');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Note, if you want the original points included in the set of new, interpolated points,
% Add them to xInterpolated list.
subplot(3, 1, 3);
xInterpolated = sort([xInterpolated, xOriginal], 'ascend');
yInterpolated = interp1(xOriginal, yOriginal, xInterpolated);
% Plot interpolated points.
plot(xInterpolated, yInterpolated, 'bo-', 'LineWidth', 2);
% Plot training points over them so we can see where they are in relation to the new points.
hold on;
plot(xOriginal, yOriginal, 'ro', 'LineWidth', 2);
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Interpolated Points Including Training Points', 'FontSize', fontSize);
legend('Interpolated', 'Training');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
  1 Comment
Álvaro Pardo
Álvaro Pardo on 14 Aug 2018
Thanks for the answer and sorry for my late reply. I've tried the code and seems to work. However, I would like to take into account the direction between each pair of original points to calculate later the interpolated ones based on that direction. Any ideas?

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation 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!