0

I have a short question: I would like to call the matlab fuction ifft from c code (inverse fast fourier transform)

I was trying to understand the matlab api for c , but I could not find any example on how to pass the arguments or how to call an internal fuction of matlab within c code

any hint will be greatly appreciated !

Julia

2 Answers2

0

You can generate C code from a script using the MATLAB Coder app. That should make the ifft callable. The ugliest way to do it would be to exec() matlab and re-ingest its output. Oliver's answer is certainly the cleanest and best route though.

0

The way to use a c/c++ based function for MATLAB to call is to build a mex file. Basic steps are :

  1. write a c/c++ script, say you ifft()

  2. build it (using visual studio for example) to generate a .mex (.mexw64 for 64-bit system) file.

  3. call your ifft() from your MATLAB code once you have your .mex file

The interface between the MATLAB and c/c++ code should follow certain rules. Here is an example you can refer to:

https://www.mathworks.com/help/matlab/matlab_external/standalone-example.html

Here is how to build the c/c++ script into a .mex file: https://www.mathworks.com/help/matlab/ref/mex.html

The .mex file is pretty much like a library. After you build it, put it in the same folder as the MATLAB script, then you can run it.

Hope it helps.

Nick X Tsui
  • 2,737
  • 6
  • 39
  • 73