Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What is the best way to mix C and matlab?

  1. Mar 11, 2009 #1
    Hey,

    I need to modify some C codes, but I want to change the original FFT subroutine into someway that calls matlab spectrum functions. I checked the matlab help document, but still have not decided which way to go: (1) C-MEX file; (2) mcc.

    There must be some other way to go, but I have not learned enough. Anybody here is familiar with this kind of thing? Would you please give me some suggestions, or recommended approaches?

    Thank you very much.
     
  2. jcsd
  3. Mar 12, 2009 #2
    Would you prefer to call MATLAB routines from C, or C from MATLAB? I don't have any experience with calling C from MATLAB, but calling MATLAB from C is pretty easy, you just need to use the MATLAB engine API.

    This will let you run an instance of MATLAB from within your C app, and you can exchange data between MATLAB and your app, and make any MATLAB calls you like.

    Documentation is on the Mathworks web site. Look for "C and Fortran API" and "MATLAB Engine."

    Hope this is what you're looking for.

    -Kerry
     
  4. Mar 12, 2009 #3
    There is also an example on the Numerical Recipes site. www.NR.com

    Thanks
     
  5. Mar 12, 2009 #4
    Thank you so much! Yes, calling matlab from C is what I need. :smile:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook