How to generate a function from x-y vectors?
153 views (last 30 days)
Show older comments
Commented: Ghenam Dahmane on 4 Mar 2022
Hello MATLAB users. I got two vectors (say x and y). Is there any way to create a function i.e. y=f(x). I do not want the expression. I just want to create the function in matlab for further calculations. For ease: x=[1 5 0 32 8]; y=[10 1 654 32 100];
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.
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));
More Answers (3)
Yifan Ma on 6 Feb 2018
What you are looking for is map container. https://de.mathworks.com/help/matlab/ref/containers.map-class.html
Edited: Luca on 31 Mar 2020
I have 2 vector (x, y) and I desire math expression y=f(x)
x must be syms. How to?
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!