multiple interp1 without loop

16 次查看(过去 30 天)
sjohuvud
sjohuvud 2018-6-20
评论: Stephen23 2018-6-21
Hi,
interp1 handles the following input and output: Vq = interp1(X,V,Xq)
I have X, V and Xq that each have a dimension of 12 rows by 10^5 columns.
I'd like to carry out interp1 10^5 times, treating each column of data in X,V and Xq as unique datasets in interp1, but Matlab requires that input X is a vector. So it is, therefore, not possible to do the following, because X is an array in my case:
Vq(:,1:10^5) = interp1(X,V,Xq)
I could of course do a loop:
Vq = NaN(12,10^5);
for i = 1:size(Vq,2)
Vq(:,i) = interp1(X(:,i),V(:,i),Xq(:,i))
end
That works, but it is super slow.
Does anyone know of a way to do this without implementing a loop, in a way that is significantly faster than a loop?
I realise that I may be asking the impossible here.
edit: would sub2ind help me out here?
Thanks,
Bryan

回答(1 个)

Stephen23
Stephen23 2018-6-20
Try using a loop with interp1q.
  1 个评论
Stephen23
Stephen23 2018-6-21
sjohuvud's "Answer" moved here:
Thanks for the tip. Unfortunately interp1q is outdated and no longer included in my version of MatLab. As far as I can see it is the same as interp1 with linear interpolation (i.e. the default setting for interp1. It also has the same limitation of input X needing to be a vector. Do you think interp1q would be slightly faster in the loop because it is simpler?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by