## MATLAB help: Interpolating an array of data to create a function

Hi,

As the title suggests, I have a 2D array of data. Essentially, I solved a DE using matlab and it gave me the array of x against t. I want MATLAB to create a function for me by interpolation so I can use it again (to solve another different set of DEs). I've been stuck on this for a while now.

How do I go from an array of x vs t to the point where I have a function x(t)?

Thank you :)
 polyfit()? http://www.mathworks.com/help/matlab/ref/polyfit.html the function x(t) will be a polynomial, so you may or may not like that. you may want to choose another function basis, like adding up exponentials to fit your data. you might want to apply polyfit() to the logarithm of your data and then exponentiate the result. there is an unlimited number of methods to fit a deterministic function to given data. another way of looking at it is that this $x(t)$ is ideally sampled (which means $x(t)$ was bandlimited before sampling) and the $x[n]$ in the array are the samples. then you want to do bandlimited reconstruction. it might look like: $$x(t) = \sum_{n==\infty}^{+\infty} x[n] \ \operatorname{sinc}((t - nT)/T)$$ where $$\operatorname{sinc}(u) = \frac{\sin(\pi u)}{\pi u}$$
 Hi rbj, Thanks for the reply. I did see polyfit but I was hoping for something slightly different. I didn't quite understand the last part of your post but I'm guessing it's a more advanced way of finding the equation of the best fit curve. The thing is, I don't need to know what this function is (it can be polynomial, exponential or anything). I was hoping I could define a function f(t) such that if the argument is some t between my array points, MATLAB will do a linear interpolation and give me an output. I tried working with interp2 but I couldn't get what I want. Once I do this, I think (please correct me if I am wrong) I can simply use this f(t) in the same way I use one of MATLAB's built in functions like sin(t) or exp(t) which are accepted by ode45 and other differential equation solvers. Is this possible?