MATLAB-对每个X插入多个Y的2D曲线 [英] MATLAB - interpolating a 2D curve with multiple Y's per X

查看:114
本文介绍了MATLAB-对每个X插入多个Y的2D曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对数据集进行插值,但是给定的X可以具有多个Y,如下所示:

I would like to interpolate a data set, but a given X can have multiple Y's, example given below:

A(:,1:2,1)=
95.2343   70.6159
   96.4501   71.5573
   97.4430   72.7315
   98.9743   72.8699
  100.0470   71.7690
  100.3872   70.2699
  100.7797   68.7837
  102.1478   68.0814
  103.6851   68.0521
  105.0307   68.7966
  105.8972   70.0666
  106.7177   71.3665
  107.7095   72.5416
  108.9175   73.4924
  110.3574   74.0309
  111.8943   73.9859
  113.3936   73.6446
  114.6645   72.7794
  115.5911   71.5522
  116.2426   70.1591
  116.3922   68.6286
  116.3503   67.0914
  116.7771   65.6147
  117.9045   64.5692
  119.4065   64.2425
  120.9432   64.2923
  122.2526   65.0975
  122.9486   66.4682
  122.8841   68.0043
  122.5492   69.5051
  122.2403   71.0109
  122.0819   72.5402

这些是沿着蛇形物体的点,从上至下的视频进行了数字化处理.它们的姿势通常会导致每个X产生2个或更多的Y点,并且由于它们转动(通常剧烈变化),而我需要保持一致的XY框架,所以我不能只旋转X和Y.

These are points along the body of a snake, digitized from top-down video. Their posture frequently results in 2 or more Y points per X, and because they turn (often dramatically) while I need to maintain a consistent XY framework, I can't just rotate my X and Y.

我可以使用cscvn制作样条函数,并且使用fnplt绘制时看起来很棒!但是,当我尝试使用ppval取回值时,一切都变得胡扯了,我得到了两条看起来不像蛇或fnplt中所示内容的曲线.

I can make a spline function using cscvn, and when plotted using fnplt it looks great! But the moment I try to get values back using ppval, it all goes to crap and I get two curves that look nothing like the snake or what's shown in fnplt.

此处的图片: http://imgur.com/aYJ0Ftj

我想要的是将一条曲线拟合到这些点,并将该曲线转换为一系列可能包含200个XY点的

All I want is to fit a curve to those points, and convert that curve to a series of maybe 200 XY points.

我假设有一个非常简单的答案,一些我从未在搜索中找到的命令,但我一生都找不到.这远远超出了我通常的技能范围(我更习惯于在沼泽中爬行以捕捉鳞状或黏糊状的东西),所以我确定我对熟练的MATLAB用户完全忽略了一些东西.

I'm assuming that there is some obscenely simple answer, some command I've just never turned up in my searching, but I cannot find it for the life of me. This is quite far outside my usual skillset (I'm more used to crawling through swamps catching anything scaly or slimy), so I'm sure I'm overlooking something totally obvious to a skilled MATLAB user.

谢谢!

推荐答案

也许这是您已经尝试过的方法,但是注释有点小,所以这里有个想法可能会对您有所帮助

Perhaps this is what you already tried, but a comment was a bit small, so here is one idea that may help you

x = [1 2 3 4 5 6 7 6 5];
y = [1 4 4 3 2 2 2 3 4];
t = 1:length(x);
figure; plot(x,y)


xx = interp1(t,x,1:.01:length(x),'pchip');
yy = interp1(t,y,1:.01:length(x),'pchip');

hold on; plot(xx,yy,'g')

通过将x和y都作为t的函数进行插值,避免了interp的唯一值限制.

I avoided the unique values restriction on interp by interpolating x and y both as a function of t.

这篇关于MATLAB-对每个X插入多个Y的2D曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆