What is the best way to mix C and matlab?

  • MATLAB
  • Thread starter beanlet
  • Start date
  • Tags
    Matlab
In summary, the speaker is looking for a way to modify their C codes by calling MATLAB spectrum functions instead of using the original FFT subroutine. They are unsure of which approach to take, either using a C-MEX file or mcc. Another individual suggests using the MATLAB engine API to easily call MATLAB routines from C and provides resources for documentation and an example. The speaker confirms that this is the approach they need and expresses gratitude.
  • #1
beanlet
6
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
  • #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
 
  • #3
There is also an example on the Numerical Recipes site. www.NR.com

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

1. What is the difference between C and matlab?

C and matlab are two programming languages commonly used in scientific computing. C is a general-purpose programming language that is commonly used for system and application programming, while matlab is a high-level language specifically designed for numerical computing and data analysis. C is a compiled language, meaning that the code must be translated into machine code before it can be executed, while matlab is an interpreted language, meaning that the code is executed line by line. Additionally, matlab has built-in functions and tools for data analysis, while C requires the use of external libraries for these tasks.

2. Can I use C and matlab together?

Yes, it is possible to use C and matlab together in a single project. C code can be compiled into a mex file, which can then be called from matlab. This allows for the benefits of both languages to be utilized in a single project. However, it is important to note that the integration of the two languages may require some additional effort and may not always be straightforward.

3. Which language is better for scientific computing, C or matlab?

This ultimately depends on the specific needs of the project. C is a lower-level language, meaning that it offers more control and efficiency, but may require more coding and debugging. Matlab, on the other hand, is a higher-level language, which may be easier to use for data analysis but may sacrifice some control and efficiency. In general, C is better suited for tasks that require speed and control, while matlab is better for tasks that involve data analysis and visualization.

4. Is there a learning curve to using C and matlab?

Both C and matlab have their own learning curves, but it may be easier to pick up matlab for those with no prior programming experience. C requires a strong understanding of programming concepts and syntax, while matlab has a more user-friendly interface and built-in functions that can be used without extensive coding knowledge. However, to fully utilize the capabilities of either language, it may take time and practice to become proficient.

5. Are there any alternatives to using C and matlab together?

Yes, there are alternative programming languages that can be used for scientific computing, such as Python, Java, and R. These languages may offer different features and advantages compared to C and matlab, so it is important to assess the specific needs of the project before deciding on a language to use. Additionally, there are also libraries and tools available that can bridge the gap between different programming languages, allowing for the integration of multiple languages in a single project.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Computing and Technology
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top