MATLAB: How to use inputs from multiple 3D Arrays to interpolate on multiple 2D arrays

2d arrays3d arraysinterpolatemultidimensional arrays

Hello everyone, I'm having issues finding a function or thinking a way of implementing my question. I have four two-dimensional tables that each represent actual lift & drag data at different air speeds. They are in the format
Tn = [a1 L1 D1; a2 L2 D2; a3 L3 D3;...;an Ln Dn]
The amount of rows can differ between each table.
I also have two three-dimensional arrays, A & T.
A is actual a values.
T is actual air speeds.
size(A)
ans =
20 100 100
size(T)
ans =
20 100 100
I would like to take the each element value of T and find what 2D Tables it lies between. I want to then take the value of the element from A at the same location to interpolate to find values of L & D on both tables. Then I would like to take the element value from T to interpolate between both L & D values.
In the end, I hope to have a three dimensional array for L and another for D that are the same size of A & T.
Thank you all!
Extra Credit: I'm hoping to not use for loops and/or creating functions. For loops seems to slow down my code dramatically & I would like to not have to keep track of separate function m-files.

Best Answer

I'm not sure if I've found the most convenient way, but I'll post what I did in case someone runs into a similar problem.
I started with a 2D array of reynolds numbers
size(Re)
ans =
20 100
I created a temporary array of integers based on if the reynold's numbers were between values of each lookup table. I didn't need to do this as I could of set the conditions within the interpolation part of the code, but i was easier to read and imagine in my head.
tRe = re;
tRe(tRe<Re1) = 1;
tRe(tRe<Re2 & tRe>=Re1) = 2;
tRe(tRe<Re3 & tRe>=Re2) = 3;
tRe(tRe<Re4 & tRe>=Re3) = 4;
tRe(tRe>=Re4) = 5;
Then set the values that matched whatever integer I was looking for to 1 and the rest to zero. The leftover values were were than multiplied by my 20x100x100 'a' matrix. Any values that were zero still were set to nan. Then interpolated on the table.
ttRe = tRe;
ttRe = (ttRe == 1);
ttRe = ttRe.*a;
ttRe(ttRe == 0) = nan;
ttRe(end,:,:) = 0;
tCl1 = interp1(re1(:,1),re1(:,2),ttRe);
tCd1 = interp1(re1(:,1),re1(:,3),ttRe);
when interpolating between tables, I would interpolate on both tables individually and used an interpolation formula to interpolate between the two. Another temp matrix was created to apply Reynolds numbers back for use as interpolation values.
ttRe = tRe;
ttRe = (ttRe == 2);
tttRe = ttRe.*re;
tttRe(tttRe == 0) = nan;
ttRe = ttRe.*a;
ttRe(ttRe == 0) = nan;
tCl2a = interp1(re1(:,1),re1(:,2),ttRe);
tCl2b = interp1(re2(:,1),re2(:,2),ttRe);
tCl2 = (((tttRe-Re1)/(Re2-Re1)).*(tCl2b-tCl2a))+tCl2a;
tCd2a = interp1(re1(:,1),re1(:,3),ttRe);
tCd2b = interp1(re2(:,1),re2(:,3),ttRe);
tCd2 = (((tttRe-Re1)/(Re2-Re1)).*(tCd2b-tCd2a))+tCd2a;
I did that for each integer on the tRe array. At the end I set all values that were nan to zero. Since, no temp cl & cd matrices overlapped with another it was easy to just add them together. I know that if any values were truly zero then I got rid of them, but the accuracy of the data set gave a small chance that values would actually be zero. All the zero values after the matrix addition were set back to nan, so I wouldn't see them in my surf plot and the temp matrices were set to the actual variables I needed.
tCl1(isnan(tCl1)) = 0;
tCl2(isnan(tCl2)) = 0;
tCl3(isnan(tCl3)) = 0;
tCl4(isnan(tCl4)) = 0;
tCl5(isnan(tCl5)) = 0;
tCd1(isnan(tCd1)) = 0;
tCd2(isnan(tCd2)) = 0;
tCd3(isnan(tCd3)) = 0;
tCd4(isnan(tCd4)) = 0;
tCd5(isnan(tCd5)) = 0;
tCl = tCl1+tCl2+tCl3+tCl4+tCl5;
tCd = tCd1+tCd2+tCd3+tCd4+tCd5;
tCl(tCl == 0) = nan;
tCd(tCd == 0) = nan;
cl = tCl;
cd = tCd;