I need a way of obtaining a Lx2 trajectory from a Nx2 array of points, i.e. a way of connecting those points into a single trajectory (for example, create a 10000x2 array of points from a 5x2 array of points). I have tried using interp1 and interp2 but either I don't fully understand them or they don't do what I need.

有帮助吗?

解决方案

It sounds like you need to be using interp1 in a loop (i.e. to preserve original order) interpolating between each consecutive pair of points:

X = [10; 10.0001; 9; 48];   %// You can consider something like X = [10;10;9;48]; X=X+rand(size(X))*0.0001 instead of dealing with equal X values manually
Y = [10; 20; 50; 6];

m = 3333; %//num points between nodes
n = m*(length(X)-1);

Yi = zeros(n,1);
Xi = [];
for k = 1:length(X)-1
    xi = linspace(X(k), X(k+1), m);
    Xi = [Xi, xi];
    Yi(((k-1)*m+1):k*m) = interp1(X(k:k+1), Y(k:k+1),xi); 
end

plot(X,Y,'or');
hold on
plot(Xi,Yi);

To get a pentagon (not a W) try this looping code with these inputs:

X = [0.25; 0.75; 1; 0.5; 0; 0.25];
Y = [0; 0; 1; 1.8; 1; 0];

Result:

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top