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!