×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Interpolation

## Interpolation

(OP)
Hello everyone,
I need to interpolate a trajectory.
The trajectory is an array with the X and Y coordinates. The problem is that, since it is not a function, there are more that one Y value for each X and vicecersa.
For example:
Trajectory:
[1 4
2 5
3 6
4 8
5 10
6 11
7 12
9 11
10 9
9 8
8 7
7 6
7 5
8 5
9 4
11 4
12 4]
I tried to use the function interp1 but it gives me an error because my trajectory is not a function.
Since the position is stored with a frequency of 14 Hz, I have lost some information of the path. This is why I need an interpolation.
Moreover I have also multiple X for the same Y. It means that transpose the X with the Y doesn't help.
How can I do it?
There is a function that interpolates trajectory and not only function?
Is there any function in Matlab that allows me to interpolate vectors?
Andrea

### RE: Interpolation

Your biggest issue is going to be that linear interpolation will suck at accurately predicting the estimated trajectory. Your data shows lots of turns, which I assume were originally smooth changes in direction?

Are these points sufficiently accurate to use for a spline fit?

### RE: Interpolation

Interesting issue that surprisingly doesn't seem solved in the various forums. Would seem to me to be a FAQ when using interp1. Anyway, after a bit of playing I have a solution.

As you say, interp1 and friends won't do non-functions, so you need to generate an equivalent function by parameterising. By using a simple parameterisation on both the X and Y points, you get two functions that can be independently interpolated. De-parameterisation will then give you the interpolation of the original non-function.

#### CODE --> matlab

XY = <paste data from original post>;
X = XY(:, 1);
Y = XY(:, 2);
t = 0:0.1:17;
X1 = interp1(1:17,X,t);
Y1 = interp1(1:17,Y,t);
plot(X,Y,'o', X1,Y1,'-') 

Now as IRstuff goes on to say, maybe a linear interpolation is not ideal. Good news is that other interpolation functions slot right in:

#### CODE --> matlab

X1 = pchip(1:17,X,t);
Y1 = pchip(1:17,Y,t);
plot(X,Y,'o', X1,Y1,'-') 

#### CODE --> matlab

X1 = spline(1:17,X,t);
Y1 = spline(1:17,Y,t);
plot(X,Y,'o', X1,Y1,'-') 

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!