3
  • I was wondering if it would be possible that link AnyLogic to Matlab?

    I need a way that call a function from Matlab to Anylogic.

soheil
  • 31
  • 4

2 Answers2

5

At this level AnyLogic should be considered as Java application, and the question should be formulated as Link Java and Matlab. You may search for different Java libraries that establish connection with MatLab and Java app, allowing to pass commands from app to Matlab, and get the result. Example of such library — matlabcontrol. There is also example model.

UPD: Matlab provides Java API for AnyLogic, so you may directly use it within AnyLogic. In this case third-party libraries are not required. For this purpose you need to add engine.jar to the model dependencies, the .jar is provided with Matlab, it is located in: matlab\extern\engines\java\jar

Here is the model that invokes Matlab using the respective examples from: matlab\extern\examples\engines\java

Gregory Monahov
  • 711
  • 3
  • 7
3

I'm not sure which direction you are talking about.

calling a matlab function in anylogic:
Since Anylogic is based on Java, you could use the Java Runtime class, and do something like: Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("C:\<a long path here>\matlab.exe" -nodisplay -nosplash -nodesktop -r "run('C:\<a long path here>\mfile.m');exit;"

after that you need to get the output from the process object pr and do your magic.

calling anylogic simulation in matlab:
have a look at : http://help.anylogic.com/topic/com.xj.anylogic.help/html/integration/Integration.html