plot data X,y,z data as surface

6 次查看(过去 30 天)
Hi all.
I am trying to plot stress values with matlab. My file dataset is with 3 columns: x_coord, y_coord, stress (which correspond to the stress values).
I tried to use scatter but, obviously, it plot the data as a point which is not exactly what I want.
I used scatterinterpolant+surf and imagesc but the colorbar numbers are different from the real data, so I am not sure I am doing the right thing.
F = scatteredInterpolant(x_axis, y_axis,zvalue);
min_x_axis = min(x_axis);
min_y_axis = min(y_axis);
max_x_axis = max(x_axis);
max_y_axis = max(y_axis);
x= linspace(min_x_axis, max_x_axis, 100);
y = linspace(min_y_axis, max_y_axis, 100);
[X, Y] = ndgrid(x, y);
D = F(X, Y);
surf(X, Y, D, 'edgecolor', 'none');
Thanks to all who can help me.

采纳的回答

Cris LaPierre
Cris LaPierre 2020-6-1
Your code looks good. How exact are you expecting the colorbar to be? You've interpolated the data, so it's not going to exactly match.
  4 个评论
Chiara Lanzi
Chiara Lanzi 2020-6-2
Thank you!!!!Using 1000 for the grid I can see a very good improvement.
I didn't think that the grid was the problem or that it can affect so much the result. Well,now I know!!
Thank you, again.
Cris LaPierre
Cris LaPierre 2020-6-2
Just one follow up then. Your grid does not have to be equally spaced. Most of this surface can be generated with only a few points. You really only need the grid to be finer around your points of interest. If you can get the grid to exactly land on your extreme points, you can get the same max/min values.
min_x_axis = -50000
max_x_axis = 4.9936e+04
min_y_axis = -5.0000e+04
max_y_axis = 0
min_zvalue = -16.2749
max_zvalue = 1.5124
I created a scatter3 plot and used the data tip tool to identify the X and Y coordinates of the peaks. I added those to the 100x100 grid and got the same max/min values.
...
x= linspace(min_x_axis, max_x_axis); % default is 100 points
y = linspace(min_y_axis, max_y_axis);
% Add points of interest to the grid
x = sort([x -4300 0 4273])
y = sort([y -10400 -10000 -9982 -9600 -5000 0])
.
.
.
And the corresponding min/max values of the surface
min_X = -50000
max_X = 4.9936e+04
min_Y = -5.0000e+04
max_Y = 0
min_D = -16.2465
max_D = 1.5124
Of course, this is a manual process.
One item to be aware of still. The bump on the top is actually 2 separate peaks. I can see this when I explore the scatter3 plot. However, I could not get it to appear in the surface, again likely due to approximation errors when interpolating.

请先登录,再进行评论。

更多回答(0 个)

类别

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