How to number the nodes in a mesh?
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm creating a 2D mesh of a T bar but utilized the surf function as I needed to get rid of the lower left corner of the bar. So I created a third Z variable and set the boundary conditions outside of it to 0 which would get rid of the unwanted lower left corner. This gave me a 3D plot but I've shown it in a 2D view below.
I basically want to know how I can number the nodes and/or elements and display it on the plot? I feel as though I'll have to loop through it but I'm not quite sure.
x_max = 0.1; % Length of bar
y_max = 0.1; %Breadth of bar
dx = 0.004; %Square Element size
dy = dx; %Square Element size
x1 = 0:dx:x_max; %Elements in the x direction
y1 = 0:dy:y_max; %Elements in the y direction
[X,Y] = meshgrid(x1,y1);
Z = zeros(length(x1),length(y1)); %Z variable to get rid of part of T bar
Z(:,x1>=0.08)=1; %Conditions for the unwanted part
Z(y1<=0.04,:)=1; %Conditions for the unwanted part
Z(Z==0) = NaN;
surf(X,flip(Y,1),Z)
0 Commenti
Risposte (1)
Rupesh
il 21 Mag 2024
Modificato: Rupesh
il 21 Mag 2024
Hi Sean,
I understand that you want to improve the visualization of T-bar mesh by numbering its nodes and possibly its elements in a systematic way. However, this task is challenging due to the presence of NaN values in the mesh. These NaN values block the display of certain areas, especially the lower left corner of the T-bar structure.
To tackle this challenge, you can iterate through the meshgrid's coordinates (X and Y matrices) and apply text labels to represent node numbers directly on the plot. To do this, you need to iterate through each point in the mesh to determine if it belongs to the T-bar structure (i.e., if its Z value is not NaN), and then assign sequential numbers to these points. Refer to the following example code snippet to see what changes need to be made to number the nodes.
% Assuming the lower left corner (origin) is the first node and counting increases to the right and then upwards
nodeNumber = 1;
[nRows, nCols] = size(X);
for i = 1:nRows
for j = 1:nCols
if ~isnan(Z(i, j)) % Check if the node is part of the T-bar structure
% The text function places a text label at the specified coordinates
% Adjust the offsets (-0.002 in this example) as needed for visibility
text(X(i, j)-0.002, Y(i, j)-0.002, 0, num2str(nodeNumber), 'Color', 'red');
nodeNumber = nodeNumber + 1;
end
end
end
hold off;
This approach ensures that all relevant nodes are numbered and visible on the plot. To learn more about the text function refer to the following documentation
Hope it helps!
Thanks
0 Commenti
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!