Interpolating between two 3d time dependent positions
24 ビュー (過去 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
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
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
2 件のコメント
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
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!