MATLAB Answers

# Reverse calculate a table of values

3 views (last 30 days)
Ferd on 17 Jan 2020
Commented: Star Strider on 20 Jan 2020
Hi,
I'm looking for a way to determine the Y axis from a given Z value in a 3D table. Basically reverse interpolate the table.
Is there a way to determine it?
X/Y 0 100 175 250 325 400 475 575
60 0 5 13 21 29 40 51 68
80 0 7 16 24 32 40 49 63
90 0 7 16 25 34 42 49 61
100 0 6 15 25 33 41 49 59
110 0 6 15 23 32 40 48 58
120 0 5 14 22 30 38 47 57
130 0 5 13 21 29 37 45 56
140 0 5 13 21 29 37 44 55
150 0 4 12 21 29 37 44 54
160 0 3 12 20 29 37 44 53
Say, Z = 45, X = 125, Y = ?
Thanks in advance!

#### 0 Comments

Sign in to comment.

### Accepted Answer

Star Strider on 17 Jan 2020
I am not certain what a ‘3D table’ is. Perhaps you intend a three column table or array.
If that is true, then the interp1 function could be appropriate.
The code for that, assuming ‘Y’ and ‘Z’ are vectors, would be:
Yi - interp1(Z, Y, Zi);
and ‘Zi’ is the scalar or vector you want to find the ‘Yi’ values for.

#### 4 Comments

Show 1 older comment
Star Strider on 17 Jan 2020
This is an indirect way of going about this, however it appears to work:
X = [60
80
90
100
110
120
130
140
150
160];
Y = [0 100 175 250 325 400 475 575];
Z = [0 5 13 21 29 40 51 68
0 7 16 24 32 40 49 63
0 7 16 25 34 42 49 61
0 6 15 25 33 41 49 59
0 6 15 23 32 40 48 58
0 5 14 22 30 38 47 57
0 5 13 21 29 37 45 56
0 5 13 21 29 37 44 55
0 4 12 21 29 37 44 54
0 3 12 20 29 37 44 53];
[Xm,Ym] = ndgrid(X(:)',Y(:)');
F = griddedInterpolant(Xm,Ym,Z);
Yfcn = @(Yq) norm(F(Xq,Yq)-Zq);
Zq = 45;
Xq = 125;
Yi = fsolve(Yfcn, 10)
figure
mesh(Xm, Ym, Z)
hold on
stem3(Xq, Yi, Zq, '^r', 'filled')
hold off
grid on
xlabel('X')
ylabel('Y')
view(-125,40)
produces:
Yi =
466.176470534387
and:
Ferd on 20 Jan 2020
Works perfectly! Thanks!
Star Strider on 20 Jan 2020
As always, my pleasure!

Sign in to comment.

### More Answers (1)

Image Analyst on 17 Jan 2020
Edited: Image Analyst on 17 Jan 2020
Edited according to your new info in your comment to Star:
If the desired Z value is definitely in your Z matrix, then you can find them by
zMap = Z == desiredZValue; % Produces a logical matrix where it's 1 if the matrix has that Z value.
% To get the rows and columns of all the locations, do this:
[Y, X] = find(zMap);

#### 1 Comment

Ferd on 17 Jan 2020
Yeah, this works!
What if the X value is between two cells and the Z value is in-between two neigboring cells?
Find closest two cells with logical 1's if condition is met?

Sign in to comment.

Sign in to answer this question.