surf plot of custom data
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi All,
I am trying to visualize a surface plot using the Matlab surf function. Here is what I have done.
% Z is a 2D matrix
[X,Y] = meshgrid(x_vector, y_vector); % X and Y have the same matrix size as Z
surf(X,Y,Z);
The problem is not plotting across the meshgrid.
I even tried the following way
x_R = reshape(X,1,[]);
y_R = reshape(Y,1,[]);
z_R = reshape(Z,1,[]);
Z = griddata(x_R, y_R, z_R, X, Y, 'v4');
mesh(X,Y,Z);
Still not working. Any suggestion would be of great help.
Thanks.
댓글 수: 2
the cyclist
2022년 10월 20일
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar
답변 (2개)
Star Strider
2022년 10월 20일
The data are all matrices.
Unless I’m missing something, just plot them —
LD1 = load(websave('X','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162588/X.mat'));
X = LD1.X;
LD2 = load(websave('Y','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162593/Y.mat'));
Y = LD2.Y;
LD3 = load(websave('Z','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162598/Z.mat'));
Z = LD3.SC;
figure
surf(X, Y, Z, 'EdgeColor','none')
colormap(turbo)
Ax = gca;
% Ax.ZScale = 'log';
grid on
xlabel('X')
ylabel('Y')
view(115,30)
I experimented with setting the Z-axis scale to 'log' to explore the details, however that result was not optimal. (I have no idea what the data represent.)
.
댓글 수: 2
Star Strider
2022년 10월 20일
The scale in the ‘Y’ axis seems to be off by at lkeast an order-of-magnitude, and there may be other problems since the view angle needs to be rotated 180° to get the same orientation in the displayed figure. Unless the data are supposed to be the same in both plots (in that instance, there may be errors in the calculation itself that created the surface), the differences simply amount to different scaling and orientation.
F = openfig(websave('untitled','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162633/untitled.fig'));
[az,el] = view;
Ax = gca;
xl = Ax.XLabel.String
LD1 = load(websave('X','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162588/X.mat'));
X = LD1.X;
LD2 = load(websave('Y','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162593/Y.mat'));
Y = LD2.Y;
LD3 = load(websave('Z','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162598/Z.mat'));
Z = LD3.SC;
figure
surfc(X, Y, Z, 'EdgeColor','none', 'FaceAlpha',0.4)
colormap(turbo)
colorbar
Ax = gca;
% Ax.ZScale = 'log';
grid on
ylim([0 10]) % Note Limit
xlabel('X')
ylabel('Y')
title('Posted Data')
view(az+180,el+20) % Note Azimuth Change Required To Get The Same Orientation
It will be necessary for you to experiment with your calculations to get the desired result.
.
the cyclist
2022년 10월 20일
It looks like the data are there as you expect, and it is just a matter of zooming in to the correct part of the "landscape". Here I used the same idea as @Star Strider, but adjusted the extent of the Y axis, instead of using log. It's getting close to looking like the figure you expect.
load(websave('X','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162588/X.mat'),'X');
load(websave('Y','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162593/Y.mat'),'Y');
load(websave('Z','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1162598/Z.mat'),'SC');
figure
surf(X, Y, SC, 'EdgeColor','none')
colormap(turbo)
Ax = gca;
Ax.YLim = [0 30];
grid on
xlabel('X')
ylabel('Y')
view(115,30)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!