multiple interp1 without loop
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Stephen23
el 20 de Jun. de 2018
1 comentario
Stephen23
el 21 de Jun. de 2018
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?
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!