How to get a y-z; x table from a x-y; z Table Data?
2 views (last 30 days)
Show older comments
Hello. I am trying to edit the table data. Think that we have the z values according to each x and y values. Iwould like get the x values according to each y and z values.
As an example;
X=[1 2 3 4 5];
Y=[30;40;50;60];
Z=[1 2 3 4 5; 3 4 5 6 7; 5 6 7 8 10; 7 8 10 11 13];
So the table is;
Y
^ 1 2 3 4 5 -> X
| ---------------
30 ! 1 2 3 4 5
40 ! 3 4 5 6 7
50 ! 5 6 7 8 10
60 ! 7 8 10 11 13
I would like rearrange the table which looks like this:
Y
^ 1 4 7 10 13 -> Z
| ---------------
30 ! 1 4
40 ! 2 5
50 ! 3 5
60 ! 1 5
To be able to make an accurate interpolation (and no need to extrapolation); the given data table is extendable. I men it could be provided some more extra values. So the given data table could be like this :
Y
^ 1 2 3 4 5 6 7 ...-> X
| --------------------
30 ! 1 2 3 4 5 6 7
40 ! 3 4 5 6 7 8 9
50 ! 5 6 7 8 10 11 12
60 ! 7 8 10 11 13 15 16
70 ! 9 10 12 13 15 17 18
80 !10 11 13 14 16 18 20
...
And I need the z data table 1-13 only.
Accepted Answer
Stephen23
on 21 Feb 2017
Edited: Stephen23
on 21 Feb 2017
>> X = [1,2,3,4,5,6,7];
>> Y = [30,40,50,60,70,80];
>> Z = [1,2,3,4,5,6,7;3,4,5,6,7,8,9;5,6,7,8,10,11,12;7,8,10,11,13,15,16;9,10,12,13,15,17,18;10,11,13,14,16,18,20];
>> [Xm,Ym] = meshgrid(X,Y);
>> F = TriScatteredInterp(Z(:),Ym(:),Xm(:));
>> Zv = 1:13; % new columns
>> Yv = 30:10:80; % new rows
>> [Zn,Yn] = meshgrid(Zv,Yv);
>> Xn = F(Zn,Yn)
Xn =
Columns 1 through 7
1 2 3 4 5 6 7
NaN NaN 1 2 3 4 5
NaN NaN NaN NaN 1 2 3
NaN NaN NaN NaN NaN NaN 1
NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN
Columns 8 through 13
NaN NaN NaN NaN NaN NaN
6 7 7 NaN NaN NaN
4 4.5 5 6 7 7
2 2.5 3 4 4.5 5
NaN 1 2 2.5 3 4
NaN NaN 1 2 2.5 3
X values outside those defined in the original matrices are indicated with NaN. If you have a newer MATLAB version then use scatteredInterpolant (which can also extrapolate).
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!