What is the best way to mix C and matlab?

  • Context: MATLAB 
  • Thread starter Thread starter beanlet
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion centers around integrating C code with MATLAB, specifically focusing on modifying a C FFT subroutine to utilize MATLAB's spectrum functions. Participants explore various methods for achieving this integration, including C-MEX files and the MATLAB engine API.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested

Main Points Raised

  • One participant seeks advice on the best method to call MATLAB functions from C, considering options like C-MEX files and mcc.
  • Another participant suggests using the MATLAB engine API to call MATLAB routines from within a C application, highlighting the ease of this approach.
  • A third participant references an example from the Numerical Recipes site as a potential resource for further exploration.
  • A later reply confirms that calling MATLAB from C is indeed the desired approach for the original poster.

Areas of Agreement / Disagreement

Participants generally agree that calling MATLAB from C is a viable approach, but there are multiple methods discussed, and no consensus on the best method is reached.

Contextual Notes

Participants have not fully explored the implications or limitations of each method, and there may be dependencies on specific MATLAB versions or configurations that are not addressed.

Who May Find This Useful

Individuals interested in integrating C code with MATLAB, particularly those working on signal processing or numerical methods involving FFTs.

beanlet
Messages
6
Reaction score
0
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.
 
Physics news on Phys.org
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
 
There is also an example on the Numerical Recipes site. www.NR.com

Thanks
 
Thank you so much! Yes, calling MATLAB from C is what I need. :smile:
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K