File Exchange

image thumbnail


version (1.32 MB) by Mikkel Pedersen
Imports ANSYS mesh and results data


Updated 04 Jul 2020

View Version History

View License

This function reads the mesh data for all structural elements listed below, but includes corner nodes only (i.e. disregards any midside nodes). Both displacement- and stress results are imported. All data is returned in the "model" struct as explained below. The function is intended for further postprocessing FE results in Matlab.
Before using the function, the ANSYS model must be exported to a text file. Use the supplied "export.mac" to do this. In Workbench, add a "Commands (APDL)" block under "Solution" and paste in the macro contents. In Classic, run macro by clicking "File>Read input from..." and selecting the "export.mac" file. This will create the file "model.txt" located in the ANSYS working folder:
where "ANSYS_WORK_DIR" and "JOBNAME" are names chosen by yourself.
Supported element types:
- SOLID187 (3D tetrahedral solid)
- SOLID186 (3D hexahedral solid)
- PLANE42, PLANE82, PLANE182, PLANE183 (2D 4/8-node quad/triangle)
- SHELL181, SHELL281, SHELL63 (3D 4/8-node shell)

INPUTS: path\filename of the ANSYS export file "model.txt" (string).

model.filename = path + filename of the model file
model.raw = raw tables from ANSYS
.etlist = element type list: [type_no, ansys_name, internal_type]
.nlist = node list: [node_no, x, y, z]
.elist = element list: [elem_no, type_no, mat_no, node1, ..., node8, com_x, com_y, com_z]
.flist = face list: [node1, node2, node3, node4, elem_no, centr_x, centr_y, centr_z]
.stress = stress results: [node_no, Sx, Sy, Sz, Sxy, Syz, Sxz]
.disp = displacement results: [node_no, Ux, Uy, Uz, Usum] = same as above, but containing surface nodes/elements only
.nlist = same as above, but containing surface nodes/elements only
.elist = same as above, but containing surface nodes/elements only
.flist = same as above, but containing surface nodes/elements only
.stress = same as above, but containing surface nodes/elements only
.disp = same as above, but containing surface nodes/elements only = maps between names and indices for nodes, elements and faces
.node2ni = node_no (externally referenced number) -> node index in nlist
.elem2ei = elem_no -> element index in elist
.face2elem = face index -> element name
.ni2face = node index -> face index
.ni2ei = node index -> element index

There are two sub-structs in output model: "raw" and "surf". The first contains the raw reading of data from the ANSYS export (ETLIST, NLIST, ELIST, PRNSOL,S and PRNSOL,U). The second contains the same, but for a reduced surface model, which is "scooped-out" such that only the surface nodes/faces of the elements are included. This is expedient to reduce the computational load of plotting solid models (i.e. not plotting the internal nodes/elements)

1) Planar model: mesh with node numbers and stress contours with deformed shape.
2) Solid model: showing a reduced (surface only) model.
3) Shell model: showing a 3D shell structure in deformed configuration.

Cite As

Mikkel Pedersen (2021). ANSYSimport (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (28)

Mikkel Pedersen

Hi Jose
I'm now pretty sure it is due to your old Matlab version. Some Matlab behavior changes between versions, and I think this is the issue here. If you have the possibility, I recommend upgrading. It should fix it. Also, the graphics engine in Matlab changed with 2014b (I think) and is now much, much better and much faster, especially for visualizing FE models.
BR Mikkel

Jose Santelli

Hi Mikkel,
Thank you for your quick response.
I am using Matlab r2014a in a Windows 10 platform.
I did it, I changed the line 283 of your code in the following manner:
nlist = cellfun(@(str) sscanf(str,'%g'),str,'UniformOutput',false);

But it gives me this following error:

The following error occurred converting from cell to double:
Error using double
Conversion to double from cell is not possible.

Error in ANSYSimport>read_ansys_file (line 163)
nlist(nn,:) = read_node_line(cur_line);

It seems to me that I am almost there...
It will be a very useful tool for my work to export the APDL mesh+results to MATLAB
I appreciate your help!



Mikkel Pedersen

Hi Jose

I don't know why you are getting this error. I'm guessing it is something with your platform/version/settings or similar, but I would assume you can fix it, as Matlab proposes, by setting the 'UniformOutput' to false?

BR Mikkel

Jose Santelli

I am getting the following error in ANSYSImport.m when I execute any of the examples:

Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.

Error in ANSYSimport>read_node_line (line 283)
nlist = cellfun(@(str) sscanf(str,'%g'),str);

Error in ANSYSimport>read_ansys_file (line 163)
nlist(nn,:) = read_node_line(cur_line);

Error in ANSYSimport (line 40)
raw = read_ansys_file(filename);

Error in example3 (line 5)
model = ANSYSimport('model3.txt');

Can you help me to solve it? Thank you in advance

Levente Kis

Hi Mikkel!

Thank you very much for your help!

Mikkel Pedersen

Hi Levente
It seems you are trying to export the results of a modal analysis. The script was not intended for this, but rather for static structural analyses. Anyways, I think it may be fixed - your solve.out specifies the error and solution in line 553-555:

*** ERROR *** CP = 1.156 TIME= 21:54:08
The substep (MODE) number must be specified on the SET command for
buckling (ANTYPE=1) or modal (ANTYPE=2) analysis.

Try adapting the export script as ANSYS proposes: Use SET, loadstep, substep (where you set substep = mode number). The substep number is generally not included, because it is not necessary for a static structural analysis. As it is, the script will only work with a single result set, not multiple, as in the case of a modal analysis, so you've got to select just one. Good luck.
BR Mikkel

Levente Kis

Hi Mikkel!

Yes, i'm looking for it in the right folder.

Here is my solve.out file:

Mikkel Pedersen

Hi Levente
It should. Are you sure you're looking in the right folder as specified above? Otherwise, ANSYS should return an error in the solve.out file, hinting at what went wrong.
BR Mikkel

Levente Kis

Hi Mikkel!

The macro doesn't create the model.txt file for me.

Mikkel Pedersen

Hi Joost
You can make a loop in ADPL using the *DO - *ENDDO commands around the exporting commands. There is an example in the included macro, line 44. Within the loop, you can select the active load step with the stresses you want to export using the SET command. Good luck.
BR Mikkel

Joost Fioole

Hi Mikkel,

I would like to use your script to post process a Harmonic response simulation. And I was wondering how the APDL command has to be modified to obtain the results from every interval solution (every Frequency step). Now the PRNSOL, S and PRNSOL, U only give me the results at the final frequency step of the harmonic response. I'm not familiar with the APDL commands, do you know how to create a loop over all simulated frequency intervals in the harmonic response.

Thnx in advance

Allen Yu

Great Job. Thank you!

twan van de weijer

Hi Mikkel, very nice tool! Do you have any plans for this function to support remote points also (174/170 elements)? Thanks!

Serhii Tetora

Jonathan Charron

Hi, for a 3D printing study I need to figure out how to pull just the shell data for n-layers. Can anyone help? I have limited to no FEA experience and am fumbling in the dark with ANSYS Academic, but, what I need is for every layer of a part, all the perimeter nodes (including features for holes etc preferably) XY coordinates and magnitude data for those points eg. for +/- stress. What sub functions do I need to call and how? I don't understand the difference between an element and a node... thanks

Mikkel Pedersen

Thank you T_K_86. Each of the appended examples show how to plot both stresses and deformation. It uses the function 'patch' in Matlab. Try following one of those.
BR Mikkel


Great Job Mikkel!
I was able to use your function, but how can I plot the mesh or the stresses or deformation?
Thanks a lot for your help!

Mikkel Pedersen

Thanks Timothy

I guess you can "disguise" the thermal results as stresses and use the script as it is. However, the script reads the export in a fixed-width format, so your thermal results must be written in the exact same format as the stresses. You can modify the exporting ANSYS macro - the line which currently says PRNSOL,S exports the stresses. Use *VWRITE command instead to create your own user defined output.

BR Mikkel

Timothy Polom

Thank you very much for this contribution. Any feeling if this could to plot steady-state thermal results in Matlab, for example?

Vinod Handi

I followed the above given steps but my system is not generating the required .txt file. Please help if anybody could guide me where I am going wrong.

Mikkel Pedersen

Thanks Federica

I think you can just add "190" (the ansys element no.) to the list in line 127. Then it will be imported like the other shell elements, however not with any of the special results for your particular element.

BR Mikkel

Federica Pierro

Thank you for the great work. Any tips on how to modify the script to include SOLSH190? Thank you.

Mikkel Pedersen

Thanks Mojtaba

I guess there is not really any problem in including midside nodes. However, there are no stress results for the midside nodes in ANSYS. The largest stresses are always in the corner nodes. Therefore, I didn't need them;-).

BR Mikkel

Mojtaba sharifi

thanks for valuable work. whats the problem for including midside nodes?

Mikkel Pedersen

Thanks Chris. The script currently handles a single load step only, but I'm sure you can make a loop in the ANSYS APDL export code snippet and another loop calling the import script in Matlab. Should be no problem.

Chris Wolf

Worked easily, didn't take much effort on my part. Any tips on how to modify to that it exports a time series of displacements when doing a transient analysis?

Mikkel Pedersen

Thanks Xiaoye

At the moment, the script cannot read the .rst. You need to use Ansys to export the results to a text file which can then be read by the script. Eventuelly, it would be nice to extract stuff directly from the .rst, but it is much more tricky to read a binary file.

BR Mikkel


This is a good job ! And if the function can read the '.rst' file, it must be a more prefect job. Thank you so much.

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Inspired by: Read ANSYS mesh

Community Treasure Hunt

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

Start Hunting!