User login


You are here

interfacing between matlab and ansys

i have an optimization program for structural problem in Matlab software. i found design variables from  Matlab. i want to interface this program in to ansys softare to find optimum stress and strain. how can i interface matlab program in to ansys. if any sample tutorilas please send me. 


Hello sabareesme,

 To my knowledge there is a book with the title "Vibration Simulation Using MATLAB and Ansys" from Michael R. Hatch. I am sure that the source codes for the interfacing is attached to the book.


Regards, Tarik


Hello Sabareesme,

I wrote my masters thesis in MATLAB and ANSYS. So, I steered my ANSYS FE-simulations with MATLAB. If you are interested in the thesis or if you have questions, please contact me.

ma DOT jo DOT gross AT googlemail DOT com




Martin J. Gross

dileepade's picture

---dileep kumar

For further information take a look here!

Martin J. Gross

cae_sachin's picture

Hello Martin,

Thanks for Information, I am also trying to interface MatLab with ABAQUS, hopefully I can use the code or procedure as applicable for ANSYS, Well I think your Masters thesis is quite important and usefull to carry out my further work with ABAQUS. If you dont have any problem, can you please mail me your thesis softcopy on my gmail id that is- 

Dear Martin,


could you please tell me how you do that because i have to do as well. my subject is dynamic of plate by using ANSYS AND MATLAB. could you please me some related information. 

Hi Martin,


    I have written matlab code for composite plate simply supported at all 4 edges, but the problem is I want to compare it with FEM codes for same problem, I doesnt have much knowledge abt the FEM coding . Can you help me regading this 

Hello kiraniisc,

I read your blog about the fact that you are trying to figure out the FEM codes for ur Matlab problem. I am working right now on kind of the same problem with my professor. What exactely do you need to do with FEM? What is ur Matlab code doing? Is it plotting the plate? Does it calculate any results like displacement, strain or stress?

my email is bucuresticarmen at yahoo dot com


Am working on an optimization problem which requires interfacing of Ansys and MATLAB. The optimization algorithm has to send input values to Ansys, get back results and process it. Can any1 please help me in doing this? Thanks in advance.

I do this interfacing every now and then, especially for optimization problems. I always use APDL for this type of problems and run ANSYS in batch mode. So, you basically have MATLAB masterminding the cycle, initiating the optimization problem, managing ANSYS. In turn, ANSYS export a certain set of output files to be read by MATLAB' optimization algorithm and a new set of input variables are then exported to ANSYS LGW file, and so forth ! Hope this helps.

mmaaa's picture

hi, dr.m.attia

if you please send me an example for commands we wrote in matlab and ansys to make link between them

thank you

Mohammed, thanks fr that. I have conceived the process exactly as u said. But the problem is I dont have an idea of how to make these two 'communicate'..means what command written in the 'master' MATLAB code will call ansys once the first set of input data is it transfers back to MATLAB..In essence, I know what to do but not hw to do it..Any exapmles of your work will help, perhaps..

Hi vishnusworld

I do this in MATLAB or batch file to fire Ansys

system"C:\Program Files\YOUR ANSYS FOLDER" -b -i C:\YOUR WORKING FOLDER\FILE.lgw"

 Your ANSYS "File.lgw" should contain all the info necessary to extract the required field variables and saves them to files, so basically matlab would come later to work on these.


Dear Sirs,


I have a similar problem with interfacing of Ansys/ LS-DAYNA and Matlab, in that I want to optimize my problem with the help of Matlab. Do you have any experience about this problem, or Is there any batch code to do that?

Hello Dir

I need to codes matlab from FEM,Can you help me?

we are waiting your reply.

Best wishes

 i am doing research work in optimization of fixture layout.  In this regard i need to calculte the exciting frequny of miilig cutter.How to calculate the exciting frequncy of milling cutter. In ansys how th calculate the amplitude for this frequncy. How can i solve this problem



If you have finished the FEM model of milling cutter in Ansys. At the postanalysis module, operate the modal analysis, and then you can find the natural frequncy in the result.

mmaaa's picture


hellow my friends,

actually i have the same problem that i need to link ansys program to matlab so as to make make optimization on matlab from the results getten from ansys . what the exact command that can be wrtten in ansys and matlab to do this

please help me


Hi Dr.mmaaa,
I once came to this problem you referred. And I have succeed to achieve the link between matlab and ansys software. I also deat with the optimization in piezoelectric smart structure vibration. I am very pleased to explain the method to you. The whole command line in matlab program is !"C:\Program Files\Ansys Inc\v90\ANSYS\bin\intel\ansys90.exe" -b -i  E:\Folderbyuser\ansyscode.txt -o E:\Folderbyuser\fra.out, in which the firs part ( !"C:\Program Files\Ansys Inc\v90\ANSYS\bin\intel\ansys90.exe" ) is yoru ansys installation path in  computer. And the second part(E:\Folderbyuser\ansyscode.txt )  means your save path of ansys code which you have already written ahead for calling for. As for the third part(E:\Folderbyuser\fra.out) equals to a realtime file from which you can look out any step of the ansys code running.
Hope that can hlep you. If you have any question, please contact me without any hesitation.

mmaaa's picture

 hi, dr.onattacking

many thanks  for your reply, but forgive me I still confused , if please give me example or codes you have used to link ansys and matlab

thank you

This works perfect on a DOS shell (Win Start cmd)

"C:\Program Files\ANSYS Inc\v161\ANSYS\bin\winx64\ansys161.exe" -b -i C:\ANSYS\User\Ex37.log -o C:\ANSYS\User\Ex37.out

But when I put exactly the same inside a .m file and run it from Matlab (F5), 

!"C:\Program Files\ANSYS Inc\v161\ANSYS\bin\winx64\ansys161.exe" -b -i C:\ANSYS\User\Ex37.log -o C:\ANSYS\User\Ex37.out

it starts running but gets stuck while running the solver, it does not finish the solution, with an error message "Mechanical APDL has stopped working"

Any ideas why is this happening? 

I added & to keep thre cmd window open, so I can see Ansys is stuck.

There is some problem in Ansys when called from Matlab. What is it?


<p class="MsoPlainText">My problem is related to optimization, using the communication interface of MATLAB and ANSYS, my biggest problem is how to generate a script in ANSYS and this script be changed and read by MATLAB.&nbsp;Could anyone help me?Thanks in advance.&nbsp;<span style="font-family: Calibri, sans-serif; font-size: 11pt;"><br /></span></p>

Iam dealing with the optimization of piezoelectric patches on the plate for vibration control

idid an apdl code for the plate with piezo patches  and getting the frequency

now i want to do an optimization for the location of the patches on the plate using GA

any one can help me with thats

any codes 

mail :

Subscribe to Comments for "interfacing between matlab and ansys"

Recent comments

More comments


Subscribe to Syndicate