MATLAB Answers

interpolation for a matrix per row

4 views (last 30 days)
Jake Bowd
Jake Bowd on 12 Jun 2020
Commented: Jake Bowd on 14 Jun 2020
Hi,
I have a 50x91 double in a structure for which I would like to interpolate each row and save as a 50 x 101.
My script works fine if I specify a specific row to interpolate, however I cannot solve to interpolate for each row.
My code is:
% Normalising walks to 101 data points
for j = 1:size(procfiles,1);
n1=size(RESULTS.Kinematics(j).data,2); %number of samples per walk
t0=linspace(1,n1,n1); %original time vector
t1=linspace(1,n1,101); %new time vector of 101 points
RESULTS.Kinematics(j).Resampled = interp1(t0,(RESULTS.Kinematics.data),t1,'linear');
end
Many thanks in advance.
Best wishes,

  0 Comments

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 12 Jun 2020
You forgot the indexing here:
interp1(t0,(RESULTS.Kinematics(j).data),t1,'linear')
% ^^^ missing

  3 Comments

Jake Bowd
Jake Bowd on 14 Jun 2020
Hi Stephen,
When I do that I get the following error message:
Error using interp1>reshapeAndSortXandV (line 426)
LENGTH(X) and SIZE(V,1) must be the same.
Error in interp1 (line 93)
[X,V,orig_size_v] = reshapeAndSortXandV(varargin{1},varargin{2});
Error in Kinematics_Extraction (line 30)
RESULTS.Kinematics(j).Resampled = interp1(t0(RESULTS.Kinematics(j).data),t1,'linear');
Stephen Cobeldick
Stephen Cobeldick on 14 Jun 2020
Your code:
interp1(t0(RESULTS.Kinematics(j).data),t1,'linear');
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ why are you now indexing into t0 ?
Try this instead:
interp1(t0,RESULTS.Kinematics(j).data,t1,'linear');
Jake Bowd
Jake Bowd on 14 Jun 2020
Hi Stephen,
Thank you so much. I now have a working code doing what I need it too :).
Best wishes,

Sign in to comment.

More Answers (0)


Translated by