Equivalent of interp1 for several sets of sampling (same data).
1 次查看(过去 30 天)
显示 更早的评论
I would like to get over the interp1 limitation that x has to be a vector.
More clearly, I would like to interpolate the same data from several possible x vectors.
Something like
interp1(x,v,xq)
But for which x would be a matrix where each column is a possible vector. Something like that but without the loop:
x = [[1;2;3],[1.1;2.1;3.5],[0.9;2;2.7]];
for i = 1:size(x,2)
interp1(x(:,i),v,xq);
end;
Like I'm not really sure what my original x axis is, so I want to compare what it gives for some reference xq points...
Any idea?? Thanks in advance.
0 个评论
回答(1 个)
John D'Errico
2018-6-5
Sorry, but that is a limitation for a very good reason. They are different curves when you change x.
Interp1 interpolates values through a given curve. Change the curve? You need to call interp1 again.
Is a loop a bad thing here? Why should it be so? If you have multiple distinct curves, then interp1 would just need to have an internal loop anyway! So just use a loop. You already have a very simple solution. It just uses a loop.
2 个评论
John D'Errico
2018-6-5
编辑:John D'Errico
2018-6-5
Well, IF you were using a spline, then it would be more reason to say this is not possible. You are using the default, a linear interpolant, so something fairly basic. But at its heart, this is still a nonlinear operation, involving a search for which interval a value lines in, and then doing linear interpolation on that interval. Can I think of a tricky way where you could solve this? Um, yeah, probably. Is it worth it? Is it worth the effort? Um, well, probably not. At this time of the morning? Are you kidding? :)
Seriously, it would probably take a few more lines to write than it would to just write the loop, and be no more efficient and WAY less readable as to what the code does. I'd still be writing the explanation as to what it does and why it works, because people always ask for that. In fact, even if I WERE the author of interp1 (I'm not) AND I wanted to allow that as an option, I would just solve it as an internal loop inside interp1.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!