Uniform point interpolation along a line described by non-uniform distributed points
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Álvaro Pardo
le 5 Août 2018
Commenté : Álvaro Pardo
le 14 Août 2018
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
Réponse acceptée
Image Analyst
le 5 Août 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]);

Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!