How to spline 163 data points into 100 data points?

I have a data set that is a "double" class 163x1 in a numeric matrix, I would like to spline this data into 100 points instead of 163 data points.
Although I have researched and checked on the 'Help' section of spline, I have followed it to the best of my abilities and I have searched here for answers, unfortunately I have not found my answer.
Furthermore, when I run through this code that I have created it says that "Index in position 2 is larger than array. This should be less than 1".
z = [lCOMz_FS1_1]';
x1 = 0:1:99;
y1 = linspace(z(1,1), z(1,163), 100);
COMz = spline(x1,y1);
plot(x1,y1,COMz)
I'd like to thank anyone in advance for such helping me on such a simple code.

4 Comments

What are the x-coordinates that correspond to your 163 z-points ?
Is it
linspace(0,99,163)
?
Hi Torsten! Thank you for reaching out, so for context I have been working on Vicon nexus motion capture system for a project, the output it gives me are Convetional Gait Model joint angles.
However, since all the data are not normalised within the system, I am trying to normalise each joint and its angle data in my project. For e.g., my data is about the CoMz from the system but each trial is different in length, so I am trying to fit each trial data of my CoMz into 100 points (or the length of the gait cycle = heel strike to heel strike during walking) so its normalised for all data.
So my z = my data set of the CoMz of 1 trial.
x1 = was the x-coordinates for the plotting tool.
y1 = was me trying to create the z-variable into 100 points.
Honeslty, I got lost at this point when constantly looking at the 'Help' on spline and its examples.
Additionally, I have tried your simple edit of code on my one and it said "Error using linspace. Inputs must be scalars"
clc
z = lCOMz_FS1_1;
x1 = 0:1:99;
y1 = linspace(0,99,z);
COMz = spline(z,x1,y1);
plot(x1,y1,COMz)
If you have any idea to help furthermore, that would be greatly appreciated! Also if you can explain to me in brief detail maybe I can get a better understanding as well. Thank you!
You want to interpolate - thus you have to make your z-data a function of 163 x-values. And in order to interpolate your data in 100 points, you have to specify 100 points somewhere in between these 163 x-values in which you want to do this.
Example:
x = linspace(0,1,163);
f = x.^2;
xinter = linspace(0,1,100);
finter = interp1(x,f,xinter,'spline');
hold on
plot(x,f)
plot(xinter,finter)
hold off
grid on
Thank you so much Torsten! You have helped out a lot! Thank you for the kind explanation and the example provided.
You have helped me out a lot, the code worked and it worked perfectly within my system!
I truly appreciate you helping out on such a simple task.
x = linspace(0,1,163);
z = lCOMz_FS1_1;
len = linspace(0,1,100);
CoMz_interp = interp1(x,z,len,'spline');
hold on
plot(CoMz_interp)
hold off
grid on
This code game me exactly what I needed! Thank you.

Sign in to comment.

Answers (2)

I expect you want to use the spline method in the interp1 function. It may be possible to give more specific help if you upload the data. (You can attach a MAT file using the paperclip icon from the INSERT section of the toolbar.)

4 Comments

Hi The Cyclist!
Thank you for reaching out, so for context I have been working on Vicon nexus motion capture system for a project, the output it gives me are Convetional Gait Model joint angles.
However, since all the data are not normalised within the system, I am trying to normalise each joint and its angle data in my project. For e.g., my data is about the CoMz from the system but each trial is different in length, so I am trying to fit each trial data of my CoMz into 100 points (or the length of the gait cycle = heel strike to heel strike during walking) so its normalised for all data.
So my z = my data set of the CoMz of 1 trial.
x1 = was the x-coordinates for the plotting tool.
y1 = was me trying to create the z-variable into 100 points.
Honeslty, I got lost at this point when constantly looking at the 'Help' on spline and its examples.
I cannot share the data, as I have a condition with my organisation to not share this data.
But, I hope you can guide me or share some details about my situation that I am in and my code! Thank you!
Hi Cyclist,
I have tried the Inter1 function that you suggested, although it looks good, I'm not sure if this is correct for me.
Attached is my code and the plot figure of the original data and the data it gave me.
The blue plot line is the interp1 function data
The orange plot line is the original data, I believe this is in correct, please advise if you can do so! Thank you.
I didn't see this comment until after Torsten seems to have solved your problem (using interp1!), so I guess you are all set.
Yeah Torsten did help a lot, but thank you to The Cyclist for reaching out as well! I appreciate the help either way.

Sign in to comment.

See attached demo. You can easily use new values for the descriptively-named variables in the demo to do what you want.

Categories

Asked:

on 30 Apr 2024

Commented:

on 2 May 2024

Community Treasure Hunt

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

Start Hunting!