Mesh Data: Interpolating data and swapping axes

11 ビュー (過去 30 日間)
Philip So
Philip So 2018 年 9 月 21 日
回答済み: Philip So 2018 年 9 月 24 日
Hi
I have a surface plot and would like to swap the axes.
Suppose I have data like this
A = [0 1 2 3 4]; %x-axis
B = [10 11 12]; %y-axis
C = [0 5 3 8 5; 3 4 5 3 1; 6 4 9 2 1]; %z-axis
With surf(A,B,C), I can get a surface plot like this
But now I want to swap the axes for the data, so it would look like this
A = [0 1 2 3 4]; %x-axis (same)
C = [0 1 2 3 4 5 6 7 8 9 10]; %y-axis (new)
B = [??]; %z-axis (new)
How can I compute the new matrix B? I believe I will need to interpolate the data.
  1 件のコメント
dpb
dpb 2018 年 9 月 22 日
"I will need to interpolate the data."
Not interpolate but extrap-olate grossly outside the range of any data. This would be risky at best...

サインインしてコメントする。

採用された回答

Philip So
Philip So 2018 年 9 月 24 日
Thank you for the replies.
Regarding the C data having 3 occurences of '5', sorry, that was a bad example. I was trying to provide a simple example. My actual data set is much larger and is strictly increasing in both axes.
Anyway, I believe I have found a solution. It is a modification of the reverse look-up table discussed here: https://mathworks.com/matlabcentral/answers/12809-reverse-2d-lookup-table
It's modified to loop the reverse look-up table.
Here's the code, and I have provided a better example of the C matrix
A = [20 21 22 23 24]; %x-axis
B = [10 11 12]; %y-axis
C = [0 0.1 0.2 0.3 0.4; 0.1 0.2 0.3 0.4 0.5; 0.2 0.3 0.4 0.5 0.6]; %z-axis
figure(1)
surf(A,B,C)
title('Original Plot')
xlabel('A');
ylabel('B');
zlabel('C');
new_C_range = 0:0.1:0.6;
for j = 1:size(B,2)
for k = 1:size(new_C_range,2)
A_new(j,k) = interp1(C(j,:),A,new_C_range(k));
end
end
figure(3)
surf(new_C_range,B,A_new)
title('Reconstructed A')
xlabel('C');
ylabel('B');
zlabel('A');
Here's the original plot with C as the matrix
and here's the new plot with a reconstructed A matrix (yeah, I realised I reconstructed the wrong axis. In my original question, I wanted to reconstruct the B matrix instead, but the same logic applies.)
I've tried my best to compare the two plots. I believe they are identical and the algorithm is working correctly. Could someone help to double check the two plots and the algorithm? Thank you!

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 9 月 22 日
You cannot do that. Look in your original C data and see that there are three different locations at which C is 5. It is not possible to pick just one of them as being "the" correct place for 5 to occur.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by