MATLAB: Fminsearch from table or mat, choose row values

fminsearchmat

If I have .mat file or table with 5 columns A,B,C,D and E. when the code start running, get two input values using command "inputdlg" corresponding A and B.
if find closest value(row) within col A with first input value if among those row, choose one row which have closest value with second input within col B then finally choose one row and return the set of values [C D E].
For example, first input is 2, then choose 1 and 7th row. if second input is 10, within those 2 rows, finally 1st row's C D E value returned. [1.1 5.5 6.6]
Thanks!

Best Answer

I don't think fminsearch is the best way to solve this problem. Here is a different approach:
% T is your data table.
% in1 and in2 are the two input values.
T.dif1 = abs(T.A-in1);
min1 = min(T.dif1);
T1 = T(T.dif1==min1,:); % T1 has the rows of T that come closest to matching in1.
T1.dif2 = abs(T1.B-in2);
min2 = min(T1.dif2);
T2 = T1(T1.dif2==min2,:); % T2 has the rows of T1 that come closest to matching in2.
% If T2 only has 1 row, it is the row you wanted.
% If T2 has more than 1 row, I am not sure which one(s) you want.