Exact match case
%// Inputs (Added One more row to original post to include multiple match case)
A =[
0.1000 1.0000 10.0000 10.0000
1.0000 0.9000 0.4000 0.5000
1.0000 0.6000 0.5000 0.6000]
row_data = 1.0;
column_data = 10.0;
Now, if you are looking to find the values corresponding to all the matches, use this -
value = A(find(A(:,1)==row_data),find(A(1,:)==column_data))
giving us -
value =
0.4000 0.5000
0.5000 0.6000
Otherwise, if you are looking to find the value corresponding to just the first match, use this -
value = A(find(A(:,1)==row_data,1),find(A(1,:)==column_data,1))
giving us -
value =
0.4000
Also, please be mindful of the precision issues involved with floating point numbers. This shouldn't be a problem here because we have specifically mentioned the numbers and no other calculations had been done between matching and inputting the inputs.
Inexact match case
For cases when there aren't exact matches available, you can use interpolation as shown in codes next -
x = A(1,2:end)
y = A(2:end,1)
[X,Y] = meshgrid(x,y)
V = A(2:end,2:end)
row_data = 1.0;
column_data = 10.0;
value = interp2(X,Y,V,column_data,row_data)
If your Xq or Yq values are outside the X and Y ranges respectively, you need to do extrapolation, for which I think you can use scatteredInterpolant
instead of interp2
.