surf plot of custom data
9 views (last 30 days)
Show older comments
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 Comments
the cyclist
on 20 Oct 2022
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar
Answers (2)
Star Strider
on 20 Oct 2022
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 Comments
Star Strider
on 20 Oct 2022
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
on 20 Oct 2022
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 Comments
See Also
Categories
Find more on Surface and Mesh Plots 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!