multiple interp1 without loop

3 views (last 30 days)
sjohuvud
sjohuvud on 20 Jun 2018
Commented: Stephen23 on 21 Jun 2018
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

Answers (1)

Stephen23
Stephen23 on 20 Jun 2018
Try using a loop with interp1q.
  1 Comment
Stephen23
Stephen23 on 21 Jun 2018
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?

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!