Indexing a 3D Surface
4 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to create a surface plot of deflection in relation to two variables. The deflection is a function of both variables, but I cannot simply create a surface f(X,Y,Z) to represent the function. Instead, the data is listed in a table. Is there any way I can show the bounds of a surface as a function of two variables, without actually having an analytical function?
So far, I have created a matrix that can show the deflection trend as a function of the matrix indicies. I was thinking that I could create two vectors in the X and Y directions and associate their values with each matrix index. However, I am not sure if that is possible.
The first picture shows a data set that I am trying to represent. You can see that each deflection value (center) is associated with an X value (top row) and a Y value (left row). I do not have a function that relates these, but it is roughly continuous. The second picture is the surface created from a matrix of the deflection values. I need this but in terms of the X and Y values in the chart.
0 个评论
采纳的回答
Codeshadow
2020-6-2
编辑:Codeshadow
2020-6-2
You would need to pass in the x and y vectors as 2D arrays (think of it as XY coordinates for the surface). You can accomplish this using the meshgrid() function.
For example:
% Define x and y vectors
x = 1e-4:1e-4:1e-3;
y = 3:10;
% Create mesh
[X, Y] = meshgrid(x, y);
% Arbitrary 2D function/ Use your data here
Z = sin(X).*cos(Y);
% Plot figure
figure();
surf(X, Y, Z);
xlabel('X');
ylabel('Y');
zlabel('Z');
The code above produces the surface below (notice how the X and Y axes are correctly labelled):
3 个评论
Codeshadow
2020-6-3
You would need to take care of the order in which you pass your x and y vectors into meshgrid so that the dimensions of X and Y have the same dimensions as Z. For a quick sanity check in your code above, you could check if
size(X) = size(Data)
If that is not the case, I would suspect that you could try transposing your Data matrix to correctly align itself to the mesh. For example, try
surf(X, Y, Data_1.')
And see if that works.
Note that from meshgrid() documentation:
"The grid represented by the coordinates X and Y has length(y) rows and length(x) columns."
更多回答(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!