![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308651/image.jpeg)
Indexing a 3D Surface
조회 수: 1 (최근 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308588/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308591/image.png)
댓글 수: 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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308651/image.jpeg)
댓글 수: 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!