Plot a parametric equation in Matlab

血红的双手。 提交于 2019-12-11 01:17:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7408320/plot-a-parametric-equation-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!