1D Interpolation on array without using loops.
Mostra commenti meno recenti
Hello.
I have been pondering this all day.
So, I have an 3D-array, X1, of size 48 x 232 x 61. Y1 is a row vector of size 1 x 232. Each row of X1 corresponds with Y1. I want to interpolate between each row of X1 and Y1 without using any loops. The output is a 48 x 21 x 61 array, Y2_array. With loops, my code is as follows:
% make Y1 array for interpolation
logz = log(10e-8):.10:log(1080);
Y1 = d + exp(logz); % This is the 1 x 232 vector.
Y2 = ones(48,21); % Preallocating Y2 2D-array (size = 48 x 21).
Y2_array = ones(48,21,61); % Preallocating Y2 3D-array (size = 48 x 21 x 61)
% Interpolation
for S = 1:61
for T = 1:48
X1_row = X1(T,:,S);
Y2 = interp1(X1_row, Y1, X2(T,:,S));
% X2 is a 3D-array, size (48 x 21 x 61)
Y2_array(T,:,S) = Y2;
end
end
If I make the inputs of interp1 arrays, Matlab gives me the error message that X and Y need to be vectors.
I know there is a solution to this problem... any suggestion/thoughts about how to execute the interpolation without using loops?
Thanks!!
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!