Emre Turkoz
Emre Turkoz

Reputation: 868

How to use MATLAB optimization toolbox with functions outside MATLAB?

I want to utilize the optimization toolbox of MATLAB, namely the genetic algorithm.

But my function is an executible, which I wrote in C, which takes a text file as input. In this input file the variables can be set. So I want MATLAB to modify this text file, run the executible, and take the result in an iteration. Is that possible?

Upvotes: 2

Views: 838

Answers (2)

dzon
dzon

Reputation: 1

You can run *.exe files with the ! command.

Create loop in MATLAB where you will write something to *.txt, then run the C program with !name.exe, and read results in iterations.

Upvotes: 0

Franck Dernoncourt
Franck Dernoncourt

Reputation: 83407

You can call C, C++, or FORTRAN code in MATLAB by compiling your code into a MATLAB Executable called a MEX-file : http://www.mathworks.com/support/tech-notes/1600/1622.html

Then you would have to call this MEX-file in your fitness function.

Upvotes: 0

Related Questions