Hi Saeed,
I understand that you are facing an issue with creating an adaptive mesh for a 3D STL geometry in MATLAB, specifically refining a mesh in a localized region to a smaller element size.
Looking at your code I can see you are using “Hmax” in “generateMesh” function to have a target maximum element size. Looking at your workflow you can use “refinemesh” function to refine the mesh in a specific region after generating an initial coarse mesh. Here is the link to the documentation of the function. https://www.mathworks.com/help/pde/ug/refinemesh.html
You can also look into the following function “geometryFromMesh” to create geometry within the model. Here is the documentation for the same. https://www.mathworks.com/help/pde/ug/pde.pdemodel.geometryfrommesh.html
I hope this helps.