Need to interchange column and data in a 2-D Table

1 view (last 30 days)
Hi,
I have a 2D Table (table1) where the value at a location is given by z=(x,y)
I need to obtain a 2D table (table2) such that y=(x,z)
I guess some sort of interpolation is needed to fit a function such that z =f(x,y) ,then express this as y=g(x,z) and then build table2.
Kindly help with functions to be used.
Is there some Matlab command that would do this in a single step?
To change from
y1 y2 ... -->
x1 Z11 Z12
x2 Z21 Z22
|
V
to
z1 z2 ... -->
x1 y11 y12
x2 y21 y22
|
V
Thanks, Francis

Answers (1)

Walter Roberson
Walter Roberson on 31 Aug 2015
There is no command to do this in a single step. It is not generally possible mathematically. But see http://uk.mathworks.com/matlabcentral/answers/232829-how-can-i-look-up-and-interpolate-a-value-from-a-set-of-3d-gridded-data-i-am-given-y-and-z-dimensi
  2 Comments
FrancisF
FrancisF on 31 Aug 2015
Thanks Walter for the quick reply. My question is very similar to the one in the link you provided. Looks like there is no easy solution.
Walter Roberson
Walter Roberson on 31 Aug 2015
My solution there of
[numrow, numcol] = size(Z);
xcol = interp1(X, 1:numcol, X_to_search, 'nearest', 'extrap');
ycol = interp1(Z(:,xcol), 1:numrow, Z_to_search, 'nearest', 'extrap');
Y = Y(ycol);
is pretty easy, but it has different mathematical properties than the griddedinterpolant that was posted. A difficulty is that you have not defined how to handle ambiguity, since the same z value could be associated with multiple y values even for the same x -- and if your x might not be exactly what is in your original interpolation table, you get ambiguity in multiple dimensions.

Sign in to comment.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!