필터 지우기
필터 지우기

How to get a y-z; x table from a x-y; z Table Data?

조회 수: 4 (최근 30일)
ercan duzgun
ercan duzgun 2017년 2월 18일
댓글: ercan duzgun 2017년 2월 21일
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.

채택된 답변

Stephen23
Stephen23 2017년 2월 21일
편집: Stephen23 2017년 2월 21일
One solution using TriScatteredInterp:
>> 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).
  댓글 수: 1
ercan duzgun
ercan duzgun 2017년 2월 21일
Dear Stephen Cobeldick;
Thanks a lot. This works very well. This was what I needed.. Regards, Ercan

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by