How to number the nodes in a mesh?
조회 수: 13 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/590292/image.png)
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
답변 (1개)
Rupesh
2024년 5월 21일
편집: Rupesh
2024년 5월 21일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!