[英]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) 我有一个简短的问题:我想从C代码中调用matlab函数ifft(快速傅立叶逆变换)
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 我试图理解c的matlab api,但是找不到关于如何在c代码中传递参数或如何调用matlab的内部函数的任何示例
any hint will be greatly appreciated ! 任何提示将不胜感激!
Julia 朱莉亚
You can generate C code from a script using the MATLAB Coder app. 您可以使用MATLAB Coder应用从脚本生成C代码。 That should make the ifft callable.
那应该使ifft可调用。 The ugliest way to do it would be to exec() matlab and re-ingest its output.
做到这一点的最丑陋的方法是使用exec()matlab并重新输入其输出。 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. 使用基于ac / c ++的函数进行MATLAB调用的方法是构建一个mex文件。 Basic steps are :
基本步骤是:
write ac/c++ script, say you ifft() 写一个ac / c ++脚本,说你ifft()
build it (using visual studio for example) to generate a .mex (.mexw64 for 64-bit system) file. 构建它(例如,使用Visual Studio)以生成.mex(用于64位系统的.mexw64)文件。
call your ifft() from your MATLAB code once you have your .mex file 拥有.mex文件后,从MATLAB代码中调用ifft()
The interface between the MATLAB and c/c++ code should follow certain rules. MATLAB和c / c ++代码之间的接口应遵循某些规则。 Here is an example you can refer to:
您可以参考以下示例:
https://www.mathworks.com/help/matlab/matlab_external/standalone-example.html 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 这是将c / c ++脚本构建到.mex文件中的方法: https ://www.mathworks.com/help/matlab/ref/mex.html
The .mex file is pretty much like a library. .mex文件很像一个库。 After you build it, put it in the same folder as the MATLAB script, then you can run it.
生成后,将其放置在与MATLAB脚本相同的文件夹中,然后即可运行它。
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.