Interpolating between two 3d time dependent positions

21 次查看(过去 30 天)
I'm trying to interpolate between 3d position values seperated by a 1 minute timestep. I have an array of position data <x,y,z> of size [500,000 x 3]. Each row of 3 values <x,y,z> represents a point in 3d space at a specific time (ex. 2 minutes). I'm trying to interpolate between each value so that I have a timestep in my data of 1 second. So I want to generate 59 pts between minute 1 and minute 2. For example: If t1 = 1min, <x1,y1,z1> = <1,1,1> and t2 = 2min, <x2,y2,z2> = <2,2,2>, then t3 = 1min 30 seconds and <x3,y3,z3> might equal ~ <1.5,1.5,1.5> using a linear interpolation method. My inclination is to use interpn(). Could anyone direct me how to set this up?
  1 个评论
Tahariet Sharon
Tahariet Sharon 2023-3-8
I have the same problem, only that instead of 3 points in space I have a whole 3D matrix in space at a given point.
I have 10 points in time for different configuations of the 3D matrix, and I want to interpolate several time points between each data point. How to go about this?

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2021-6-1
编辑:Adam Danz 2021-6-1
There are multiple ways to do this. Here I show how to put your (x,y,z) coordinates into a timeseries and use resample to interpolate the 3D coordinates.
Main functions
Create an mx3 matrix of [x,y,z] coordinates
xyz is the only input in this demo. The rest of the demo can be copy-pasted.
th = linspace(0,31.5,50)';
xyz = [sin(th),cos(th),th];
Create a timeseries object at 2-minute intervals and interpolate at 60-sec intervals
Create an mx1 vector of time stamps at 2-minute intervals
timestamps = (0:2:size(xyz,1)*2-1)'; % minutes; col vector!x
Create a timeseries object
ts = timeseries(xyz, timestamps, 'Name', 'XYZdata'); % name optional
ts.TimeInfo.Units = 'Minutes';
Create an nx1 vector of time stamps at 1-second resolution. The vector spans the range of timestamps in your raw-data.
timestampsInterp = ts.Time(1) : 1/60 : ts.Time(end);
Interpolate, or resample at the new timestamps created above. Interpolation is linear by default; see the timeseries interpolation method in ts.DataInfo.Interpolation. See other interpolation options in resample>interpmethod and timeseries>DataInfo.
tsInt = resample(ts,timestampsInterp);
Extract the interpolated xyz data to an nx3 matrix (xyzInt). Note that this step could be skipped and you could work with the interpolated timeseries object directly.
xyzInt = tsInt.Data;
Plot the original and interpolated data
If you're planning on plotting your data, you may want to plot a subsection of the data since it is much larger than these demo data and will take a long time to render and will comsume much memory.
figure()
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'bo','LineWidth',2,'DisplayName','Original (2-min)')
hold on
plot3(xyzInt(:,1),xyzInt(:,2),xyzInt(:,3),'r.','MarkerSize',3,'DisplayName','Interpolated (1-sec)')
grid on
legend('Location','SouthOutside')
Store the new interpolated data in a timetable
This, of course, is optional but it will be useful if you're planning on doing further time-based analysis.
TT = array2timetable(tsInt.Data,...
'RowTimes',seconds(tsInt.Time*60), ...
'VariableNames', {'x','y','z'});
head(TT) % view the first few rows
ans = 8×3 timetable
Time x y z _____ _________ _______ _________ 0 sec 0 1 0 1 sec 0.0049957 0.99834 0.0053571 2 sec 0.0099914 0.99667 0.010714 3 sec 0.014987 0.99501 0.016071 4 sec 0.019983 0.99335 0.021429 5 sec 0.024979 0.99168 0.026786 6 sec 0.029974 0.99002 0.032143 7 sec 0.03497 0.98836 0.0375
  2 个评论
Adam Danz
Adam Danz 2021-6-2
Another approach may be to convert the data to a timetable at 2 min intervals and use retime to interpolate to seconds.
Tahariet Sharon
Tahariet Sharon 2023-3-8
I have the same problem, only that instead of 3 points in space I have a whole 3D matrix in space at a given point.
I have 10 points in time for different configuations of the 3D matrix, and I want to interpolate several time points between each data point. How to go about this?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by