Actually, by looking at the Matlab documentation I found a simpler way. You can use the function griddata. (The doc in matlab help shows visual example). The resampling on a common grid and the interpolation is embedded in the function.
%// First separate (and name your column to identify them better)
t = d(:,1) ;
x = d(:,2) ;
y = d(:,3) ;
%// use the function 'griddata'
[TI,YI] = meshgrid( 20:30 , 0:20:500 ) ; %// change these values to change the grid limits
XI = griddata(t,y,x,TI,YI) ;
%// show result in 3D ... but could be projected in X-Y plane if necessary
plot3(TI,YI,XI , 'Marker','o' )
xlabel('Time') ; ylabel('Y') ; zlabel('X')
The last line of the code shows this plot:
All your interpolated data are in the XI matrix. The way to retrieve them depends on how you want to organize them ultimately.
EDIT: To place all the interpolated data in a single table
InterpData
organized the same way of your original table, use the following:
nLine = numel(XI) ;
InterpData = [ reshape(TI,nLine,[]) reshape(XI,nLine,[]) reshape(YI,nLine,[]) ] ;
Regarding the
NaN
s. They will come to bother you every time you ask to do an interpolation outside of the initially known values.For example, if your time in the original data is in the [20 to 30] interval, matlab will gladly interpolate anything within that interval, but will return
NaN
if you ask to return a value for time = 19 for example. Same goes for Y
, the grid on which to interpolate has to be within the initial range. (as in this implementation we use a base grid formed by Time
(column 1) and Y
(column 3), to interpolate the X
column).