Azzera filtri
Azzera filtri

draw a mesh by entering elements and nodes by Location

12 visualizzazioni (ultimi 30 giorni)
Having matrix of different nodes with their location, how we can plot a mesh and exert a code on the nodes?
Imagine there are 4 differet type of nodes, with index number of 1,2,3 and 4, total number of 16. A very simple material matrix can be for instance : M=[1,1,1,1,1,1,1,2,2,3,4,4,4,4,4,4], and the corresponding location matrixs are: x=[0.1, 0.2, 0.3, 0.4, 0.2, 0.3, 0.4, 0.2, 0.3, 0.4, 0.2, 0.3, 0.4] and y=[0.1, 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3, 0.4, 0.4, 0.4]. So this domain is the following where the numbers are different type of nodes.
So, how this input can be applied in matlab?

Risposte (1)

Vinayak Gupta
Vinayak Gupta il 9 Feb 2023
Hi Sara,
To my understanding, you want to create a mesh plot for a set of nodes with their given location (in X, Y).
Taking your example, you need to pre-process the given arrays into a set of three matrices as the mesh function requires. You can read about mesh function here.
Also, the arrays in your question were not appropriately sized as M has 16 elements, while the others have 13 elements, respectively. I have assumed values based on the image attached.
M= [1,1,1,1,1,1,1,2,2,3,4,4,4,4,4,4];
x= [0.1, 0.2, 0.3, 0.4, 0.1, 0.1, 0.1, 0.2, 0.3, 0.4, 0.2, 0.3, 0.4, 0.2, 0.3, 0.4];
y= [0.1, 0.1, 0.1, 0.1, 0.2, 0.3, 0.4, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3, 0.4, 0.4, 0.4];
Assuming x and y represent locations, we will convert these into a mesh grid of unique and sorted values. We require sorted values to plot data sequentially and avoid unnecessary folds
X = unique(x);
Y = unique(y);
[X, Y] = meshgrid(X, Y);
Now, we will create a matrix Z of the same size as X and Y. And then fill in the values of M according to their positions. Z will be our nodal matrix.
Z = zeros(size(X));
for i=1:16
Z(X == x(i) & Y == y(i)) = M(i);
end
Now, we have the required three matrices, and we can pass them to the mesh function.
mesh(X, Y, Z);
And we should get an output figure as this one.

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by