# interpolation of coordinates in space using interp3

조회 수: 13 (최근 30일)
Alberto Acri . 2023년 10월 1일
답변: Torsten . 2023년 10월 1일
Hi! I have this coordinate set (C_new). I would like to add additional coordinates using interpolation.
figure
plot3(P(:,1),P(:,2),P(:,3),'k*','Markersize',20);
hold on
plot3(C_new(:,1),C_new(:,2),C_new(:,3),'r.','Markersize',10);
hold off
axis equal I'm proceeding as follows but I don't know if it's the right procedure:
X = C_new(:,1);
Y = C_new(:,2);
Z = C_new(:,3);
[Xq,Yq,Zq] = meshgrid(X,Y,Z);
Vq = interp3(X,Y,Z,V,Xq,Yq,Zq);
but what should I put for V?
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Dyuman Joshi 2023년 10월 1일
You need the equation/relation between the coordinates to interpolate, V contains the values of the the function corresponding to (X,Y,Z).

댓글을 달려면 로그인하십시오.

### 채택된 답변

Voss 2023년 10월 1일
편집: Voss 님. 2023년 10월 1일
interp3 is for interpolating a function of 3 variables, i.e., if you had a function f(X,Y,Z) that returns a value for each (X,Y,Z) then you could use interp3 to interpolate those values to new points in 3D space. In this case there is no function, only the points in 3D space, so you can define a parameterizing variable and use interp1 to interpolate each of your X, Y, Z in terms of that
% original number of points:
n = size(C_new,1);
% number of points you want (change this as desired):
n_new = floor(n/2);
d = sqrt(sum(diff(C_new,1,1).^2,2));
% cumulative distance around the ring, starting with point #1:
t = [0; cumsum(d)];
% new distances (equally-spaced) at which to calculate the new (X,Y,Z) coordinates:
t_new = linspace(t(1),t(end),n_new);
% interp1 C_new from t to t_new:
C_interp = interp1(t,C_new,t_new);
% plot:
figure
plot3(C_interp(:,1),C_interp(:,2),C_interp(:,3),'g.','Markersize',6);
hold on
plot3(C_new(:,1),C_new(:,2),C_new(:,3),'r.','Markersize',10);
axis equal 댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

Torsten 2023년 10월 1일
Given two points
P1 = [1 3 4];
and
P2 = [3 6 -1];
you can connect them by a line
s = @(t) (1-t)*P1 + t*P2;
and choose points between them:
t = [0:0.2:1];
Pq = reshape(cell2mat(arrayfun(@(t)s(t),t,'UniformOutput',0)),3,[]).'
Pq = 6×3
1.0000 3.0000 4.0000 1.4000 3.6000 3.0000 1.8000 4.2000 2.0000 2.2000 4.8000 1.0000 2.6000 5.4000 -0.0000 3.0000 6.0000 -1.0000

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

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

Start Hunting!