How to generate a function from x-y vectors?
64 ビュー (過去 30 日間)
古いコメントを表示
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];
2 件のコメント
the cyclist
2017 年 2 月 6 日
Your question is not clear. What does "use these vectors in function form" mean?
Do you mean you want to find a function f(x) that will (approximately?) fit the x-y data? If so, what type of function? A polynomial?
採用された回答
Nicolas Schmit
2017 年 9 月 4 日
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 件のコメント
その他の回答 (3 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!