How to keep positions of node/element number labels consistent with various FE mesh resolution?

3 Ansichten (letzte 30 Tage)
I have a function plotting the FE mesh with node numbers and element numbers displayed. For (meshx,meshy) = (30,15), the positions of node/element number labels look perfect for me. I.e., node number shown on the bottom-right corner of the corresponding node; element number shown on the center of the corresponding element. However, as I scale FE mesh to (meshx,meshy) = (100,50), the positions of those labels moved away... How do I adpat the code so that the positions of those labels can be scaled with different mesh resolution?
function plotGrid(meshx, meshy)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Plot FE mesh and diaplay node numbers as well as element numbers
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialization of figure object and variables
figure('Name', 'Finite Element Mesh', ...
'Numbertitle','off', ...
'Position', get(0, 'Screensize'));
nNodes = (meshx+1)*(meshy+1);
nElements = (meshx)*(meshy);
[X_nodes,Y_nodes] = meshgrid(0:meshx, 0:meshy);
[X_elements,Y_elements] = meshgrid(linspace(0.5, meshx-0.5, meshx), linspace(0.5, meshy-0.5, meshy));
% Plot the grid lines
plot(X_nodes, Y_nodes, 'k', X_nodes', Y_nodes', 'k');
title('Finite Element Mesh');
subtitle({sprintf('(meshx, meshy) = (%i, %i)', meshx, meshy), ''});
set(gca,'YDir','reverse');
set(gca,'XTick',[],'YTick',[],'XColor','None','YColor','None');
% Create the lists of node numbers and element numbers
nodeNumbers = mat2cell(num2str((1:nNodes)'), ones(nNodes,1));
elementNumbers = mat2cell(num2str((1:nElements)'), ones(nElements,1));
% Insert the labels for node numbers and element numbers
text(X_nodes(:), Y_nodes(:)+0.1, nodeNumbers, 'FontSize', 8, 'Color', 'k');
text(X_elements(:)-0.1, Y_elements(:), elementNumbers, 'FontSize', 10, 'FontWeight', 'bold', 'Color', 'r');
end

Antworten (1)

Prateekshya
Prateekshya am 7 Okt. 2024
Hello @hmhuang,
The figure you get with the parameters 100 and 50 is identical with the other one. Normally, the visual difference is because of the difference in sizes of the graphs. You can see the figure by zooming in. Here is a screenshot of the same.
I hope this helps!

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by