draw a mesh by entering elements and nodes by Location
16 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1231077/image.png)
So, how this input can be applied in matlab?
0 个评论
回答(1 个)
Vinayak Gupta
2023-2-9
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.
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!