surf plot of custom data

9 次查看(过去 30 天)
Arefin Shamsil
Arefin Shamsil 2022-10-20
评论: Star Strider 2022-10-20
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
the cyclist 2022-10-20
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar
Arefin Shamsil
Arefin Shamsil 2022-10-20
Thank you for replying. Here are the X, Y, Z data.

请先登录,再进行评论。

回答(2 个)

Star Strider
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 个评论
Arefin Shamsil
Arefin Shamsil 2022-10-20
编辑:Arefin Shamsil 2022-10-20
Thank you so much for your insight. I am attaching the figure of how it should ideally look like (but it contains some error). Notice in my attached figure, the frequency (Y-axis) runs from 50 to 300 Hz, which is really the Y dimension of the Z matrix. And the Z data is nicely spread across the XY grid.
But rather it should be from 0 to 400 Hz, which is what you've got. Notice in your plot, how the hills are all squashed against just one axis. That should not be the case. That is the error in my surf plot that I cannot resolve.
Star Strider
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
xl = 'Image column marks'
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
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)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by