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.

 Respuesta aceptada

Codeshadow
Codeshadow el 2 de Jun. de 2020
Editada: Codeshadow el 2 de Jun. de 2020

0 votos

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

Lucas Allegrette
Lucas Allegrette el 2 de Jun. de 2020
Thank you for your answer! I see, and that works well if you have Z = f(X, Y). But the dillema that I have is that Z is not a function of X and Y (or not one that I know of). I merely want to associate each value Z with one X and one Y for visualization purposes, so that the surface is just like the chart. When I try to use meshgrid(X, Y, Z), where Z is the deflection matrix, the dimensions do not match since Z is an n by m matrix, and X and Y are 1 by m and n by 1 matrices respectively. The code I am using that returns that error is shown below.
[X,Y] = meshgrid(1e-4:1e-4:1e-3, 3:10);
surf(X,Y,Data_1)
Codeshadow
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."
Lucas Allegrette
Lucas Allegrette el 3 de Jun. de 2020
That worked! It turns out that the meshgrid was one element larger than it needed to be (whoops!).

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2018b

Preguntada:

el 2 de Jun. de 2020

Comentada:

el 3 de Jun. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by