Azzera filtri
Azzera filtri

interpolation of coordinates in space using interp3

10 visualizzazioni (ultimi 30 giorni)
Hi! I have this coordinate set (C_new). I would like to add additional coordinates using interpolation.
load C_new
hold on
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 Commento
Dyuman Joshi
Dyuman Joshi il 1 Ott 2023
You need the equation/relation between the coordinates to interpolate, V contains the values of the the function corresponding to (X,Y,Z).

Accedi per commentare.

Risposta accettata

Voss il 1 Ott 2023
Modificato: Voss il 1 Ott 2023
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
load C_new
% original number of points:
n = size(C_new,1);
% number of points you want (change this as desired):
n_new = floor(n/2);
% distance between adjacent points:
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:
hold on
axis equal

Più risposte (1)

Torsten il 1 Ott 2023
Given two points
P1 = [1 3 4];
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


Scopri di più su Interpolation in Help Center e File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by