Interpulating multipule sets of data without loops
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am trying to do 1D interpulation on multipule sets of data without using loops.
If I must use a loop, the code would look as follows:
X ; % set of grid points, where each column is a different set
V ; % set of data points, where each column is a different set
xq ; % new grid points I would like to interpulate V at.
% Note that size(X) is the same as size(V) and they are both 2D
% All these values are defined priorly in the code.
Vq = zeros(length(xq),size(V,2)) ;
for i=1:size(X,2)
Vq(:,i) = interp1(X(:,i),V(:,i),xq);
end
Is there a way I can run a simular algorithem without running this loop?
Thank you in advance.
Respuestas (1)
Tejas
el 12 de Nov. de 2024 a las 6:54
Hello Ariel,
To perform 1-D interpolation on multiple sets of data without using a loop, consider these steps:
- Create a function handle that utilizes the 'interp1' function for 1-D interpolation on a given column of 'X' and 'V'.
interpFcn = @(col) interp1(X(:, col), V(:, col), xq);
- Use 'arrayfun' to apply this function to each column of 'X' and 'V', storing the results in 'Vq'.
Vq = arrayfun(interpFcn, 1:size(X, 2), 'UniformOutput', false);
Vq = cell2mat(Vq);
For more information on the 'arrayfun' function, refer to this documentation: https://www.mathworks.com/help/releases/R2021a/matlab/ref/arrayfun.html
0 comentarios
Ver también
Categorías
Más información sobre Interpolation 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!