multiple interp1 without loop
조회 수: 17 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Stephen23
2018년 6월 20일
댓글 수: 1
Stephen23
2018년 6월 21일
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!