PengOne
PengOne

Reputation: 48398

Plot a parametric equation in Matlab

I have two sets of data: [t1 ; x] and [t2 ; y], where the ts are in the same range for both, but possibly taking different values. A simple example:

[t1 ; x] = 
     1     2     4
     1     4    16

[t2 ; y] =
     1     3     5
     1     9    25

Here the underlying functions are simple: x = t1.^2 and y = t2.^2. My goal is to get a plot of x versus y. Since the values taken by t aren't the same, I cannot simply use plot(x,y). For the example, since x == y, I should get a line of slope 1, but plot(x,y) isn't straight and neither piece has slope 1.

The application is much more complicated than this simple example, and I do not have an underlying function to generate data points. The data are sparse at times, so I cannot afford to lose information by throwing out points that are not in common between t1 and t2.

I'm hoping that Matlab has some built in function that can take the two data sets and extract the dependence between x and y leaving t as an unseen parameter. Anyone know of such a function? In lieu of that, I'm open to suggestions for a good way to go about writing one.

Upvotes: 2

Views: 7125

Answers (1)

Jonas
Jonas

Reputation: 74940

I suggest using splines for this.

Given tx,x,ty,y, you can generate a graph of x vs y for a range of time points timeRange the following way using the SPLINE command:

xx = spline(tx,x,timeRange); %# interpolate x vs time
yy = spline(ty,y,timeRange); %# interpolate y vs time

plot(xx,yy);

If the underlying data are noisy, then you may want to use smoothing splines (e.g. CSAPS), which need, however, the Curve Fitting Toolbox.

Upvotes: 2

Related Questions