MATLAB: Help needed with finding corresponding index values for given table value

2d table interpolate lookup

Hi,
i would like to do the following:
i have a two-dimensional table (see http://pastebin.com/raw.php?i=p7DQrCKT) where i have in the table cells combustion temperatures (Tc) as function of a certain propellant mixture ratio (MR) (varying horizontally in table) and combustion chamber pressure (pc) (varying vertically in table).
what i would like to achieve is to find the MR and pc combination for a given Tc value. An additional catch is that the TC value is most of the time not exactly the same as the TC values in the table hence simple 'find' will not work (also it won't work because i am not interested in the indices); in other words the algorithm should interpolate between the available Tc values in the table and find the location where the desired Tc value would be located and output the corresponding (interpolated) MR and pc values.
The data in the table is such that only one unique MR and pc combination is possible for a given Tc, hence no multiple solutions are possible.
I know when i want to find the Tc value for a given MR and pc, i can use:
mixtureratio = data(1,3:11); pressure = data(3:19,1); specificheat = data(3:19,3:11); [X,Y] = meshgrid(mixtureratio,pressure); Tc = interp2(X,Y,temperature,MR,pc);
where data is the matrix containing the data read from the text file as given in http://pastebin.com/raw.php?i=p7DQrCKT
But now i hence want to achieve the exact opposite and wonder if this can be easily done with some matlab function or someone has a tip how i could address this problem?
thank you in advance for looking at this question! kind regards,
Ruwan

Best Answer

As Iain said, you've got more unknows than equations. I've come up with a possible solution, but I don't know how robust it is. It involves finding the closest temperature, isolating it and all its neighbouring nodes, and using fminsearch to interpolate.
Cols = [1 1.5 2 2.5 3 3.5 4 4.5 5];
Rows = [4:4:52];
tempMat = [2350.70 2904.03 3075.05 3075.39 3024.47 2956.58 2881.53 2802.72 2721.67
2357.33 2948.86 3147.28 3150.22 3093.38 3017.43 2933.81 2846.51 2757.39
2360.42 2972.96 3189.15 3194.13 3133.54 3052.44 2963.42 2870.86 2776.87
2362.31 2989.02 3218.58 3225.29 3161.89 3076.94 2983.91 2887.51 2790.03
2363.62 3000.87 3241.22 3249.44 3183.78 3095.73 2999.49 2900.05 2799.84
2364.60 3010.14 3259.56 3269.14 3201.58 3110.91 3011.99 2910.04 2807.60
2365.37 3017.69 3274.94 3285.78 3216.57 3123.64 3022.41 2918.30 2813.98
2366.00 3024.02 3288.18 3300.17 3229.50 3134.56 3031.30 2925.32 2819.37
2366.52 3029.43 3299.77 3312.84 3240.86 3144.12 3039.05 2931.40 2824.02
2366.97 3034.15 3310.08 3324.16 3250.99 3152.61 3045.90 2936.76 2828.09
2367.35 3038.30 3319.34 3334.38 3260.12 3160.24 3052.03 2941.53 2831.71
2367.69 3042.00 3327.75 3343.70 3268.42 3167.16 3057.56 2945.83 2834.95
2367.99 3045.34 3335.44 3352.26 3276.04 3173.48 3062.61 2949.73 2837.89];
%temperature to match:
Target = 3250;
%find the temperature closest to the target and isolate its neighbours to
%form a 3x3 matrix
[~,I] = min(abs(tempMat(:) - Target));
[x y] = ind2sub(size(tempMat),I);
%use fminsearch to interpolate within this region to find row and column
%values
tempNearest = tempMat(x-1:x+1,y-1:y+1);
rowsNearest = Rows(x-1:x+1);
colsNearest = Cols(y-1:y+1);
[X Y] = meshgrid(rowsNearest,colsNearest);
Mat = cell(4);
Mat(2:4,2:4) = num2cell(tempNearest);
Mat(1,2:4) = num2cell(colsNearest);
Mat(2:4,1) = num2cell(rowsNearest);
disp('Isolated Temperature Matrix:')
disp(Mat)
%function to find the interpolated values:
fcn = @(a) abs(interp2(X,Y,tempNearest,a(1),a(2)) - Target);
%run fminsearch to find values
I_int = fminsearch(fcn,[rowsNearest(2),colsNearest(2)]);
rowSearch = I_int(1)
colSearch = I_int(2)