Import mesh from Matlab to Ansys with additional properties of each element
Show older comments
I have obtained a finite element mesh of an image using im2mesh file by JieXian Ma. I want to export it to Ansys, but I need not to just export a mesh (it's already implemented in this file), but first I have to assign Modulus of Elasticity value to each of the node.
From the image I have I've also obtained color intensity matrix (in grayscale). I multiplied it by Elasticity Modulus I have (it represents the non-homogeneity of a bone) and then I need to somehow assign this matrix's values to the mesh.
Mesh consists of verticies (n-by-2) (x and y coordinates) and triangles (m-by-3) (numbers of verticies building up a triangle) vectors. The matrix is a square one.
Also I consider removing zeros from the matrix, as it's not needed in the mesh creation, but then it transforms into a long vector, longer than previous ones and I don't know how to do it normally.
So, maybe someone knows how to assign values to the mesh?
Below are the images of the mesh, bone image and vectors and a color matrix I have.



10 Comments
Mario Malic
on 6 May 2024
Also I consider removing zeros from the matrix, as it's not needed in the mesh creation, but then it transforms into a long vector, longer than previous ones and I don't know how to do it normally.
You probably did not index into matrix properly.
The way you could tackle the problem, the fastest - create a simple model in ANSYS with triangular mesh with few elements. Export it to the .bdf or whichever NASTRAN format. Open it with text editor and find the points, material and elements definition so you can replace with your data. You are looking for CTRIA3, here is some documentation. https://help.autodesk.com/view/NINCAD/2022/DEU/?guid=GUID-F14EFBCD-CF81-4F42-A459-0B1B8D871A6C
Maksim
on 7 May 2024
Mario Malic
on 7 May 2024
Okay, I would suggest to take a step back and try to understand your problem and how to get to the end goal - which is your question.
MATLAB - do MATLAB Onramp first, your institution may have access to courses on MATLAB Academy, they are useful too.
FEA - Try to understand the concepts first and the usual workflow of simulation: geometry, material definition, meshing, boundary conditions. You only need first three for now.
At least I don't understand how material definition is connected with GRID points. It's not, because it's the geometry definition. I see that you have defined the material, you should mesh it too, with triangular elements. Once you do that, and export the file you will find CTRIA section. From there it will be obvious where material properties are assigned.
Then comes the MATLAB part, where you use your data to write an input file that adheres to NASTRAN format. Maybe your supervisor imagined it different way, consult him.
Maksim
on 9 May 2024
Mario Malic
on 9 May 2024
Edited: Mario Malic
on 9 May 2024
Let's split this into tasks:
- Obtain mesh - you have vert and tria, tria describes the vertices that form one triangle.
- Identify mesh to be removed - removing the parts that represent air. So, you have an RGB (I assume) image and it has 3 channels - one pixel in the image is described by 3 elements in a 3D array that share the same row and column. If the node represents air then all three of those are equal to 0. How do you code that? Do the courses please or figure it out by yourself.
- Remove identified nodes and elements - You will get indices of nodes that correspond to air and you have to remove triangles that consist of these identified nodes, nodes too afterwards. You should have the mesh now, but maybe it will need some tuning/fixing.
- Applying stiffness to element - find color intensities of nodes that form each triangle, average them and you have the number.
Maksim
on 10 May 2024
Mario Malic
on 10 May 2024
I get it now, this could be interesting for people with image processing knowledge, as I don't know a lot about it. I think you should post another question that focuses only on that aspect of your task.
When you don't remove the "air", what's the output of below code? It could be that each pixel is represented by a grid that has evenly spaced points by 1.
numel(unique(vert(:,1)))
numel(unique(vert(:,2)))
If it's related to the size of gray_matrix, then it's great.
Maybe you can use scatteredInterpolant for this purpose, however, not sure if it's appropriate in this case.
Maksim
on 12 May 2024
Maksim
on 13 May 2024
Answers (1)
Jiexian Ma
on 6 Apr 2025
0 votes
Hi Maksim,
In the new version of Im2mesh package, the mesh can be exported as msh file. You can open the msh file in Gmsh (free software) and save the mesh as other file format (see below).
inp (Abaqus), key (LSDYNA),
celum, cgns, diff (Diffpack 3D),
unv (I-deas Universal), ir3 (Iridum), med,
mesh (INRIA Medit), mail (CEA Triangulation),
m (Matlab), bdf (Nastran Bulk Data File),
off (Object File Format), p3d (Plot3D Structured Mesh),
stl (STL surface), wrl (VRML surface), vtk (VTK),
dat (Tochnog), ply2 (PLY2 Surface), su2,
neu (GAMBIT Neutral File), x3d, _0000.rad (RADIOSS BLOCK)
I'm not sure which format is better for ANSYS. Good luck!
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!