# How to generate a function from x-y vectors?

186 views (last 30 days)

Show older comments

Ajay Goyal
on 6 Feb 2017

Commented: Ghenam Dahmane
on 4 Mar 2022

##### 2 Comments

### Accepted Answer

Nicolas Schmit
on 4 Sep 2017

You question is not very clear, so I will try to guess what you are trying to do.

If you want to define a purely symbolic function f(x), use the following syntax.

syms f(x)

If you want to create a function from data points x and y, use the griddedInterpolant function to create a interpolation of x and y.

x=[1 5 0 32 8];

y=[10 1 654 32 100];

[~, index] = sort(x);

F = griddedInterpolant(x(index), y(index));

##### 2 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!