简体   繁体   中英

call matlab ifft from c

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

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.

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

  1. write ac/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM