Indexing a 3D Surface
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lucas Allegrette
el 2 de Jun. de 2020
Comentada: Lucas Allegrette
el 3 de Jun. de 2020
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 comentarios
Respuesta aceptada
Codeshadow
el 2 de Jun. de 2020
Editada: Codeshadow
el 2 de Jun. de 2020
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 comentarios
Codeshadow
el 3 de Jun. de 2020
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."
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!