How can I call a .C function compiled with Matlab Coder in R?

I would like to call a C function compiled using Matlab Coder in R for later use in a Shiny app. How can I go about doing this. The top of the .C function looks like this:
double ensembleBaggedTreesExtendedStay_V1(double TransferredYesNo,
double BleedDisYesNo,
double PreOpAlbumin, double PreOpHCT,
double ASAClass, double ComplexYesNo)
and the file name for the c function is "ensembleBaggedTreesExtendedStay_V1.c"
I have very limited knowledge of R and .C and I would appreciate any help.

답변 (1개)

Harsh
Harsh 2025년 1월 2일
Hi Arsalan,
Proceed with the steps outlined below to call the C function generated by MATLAB coder in R using .C( )
  • Modify your ensembleBaggedTreesExtendedStay_V1 function such that it returns void and stores the desired result in one or more arguments expressly created for this purpose. Also, the function should have a C_ prefix.
  • Compile the function into a shared library accessible to R using this command:
R CMD SHLIB ensembleBaggedTreesExtendedStay_V1.c
  • Within an active R session, link to the shared library using dyn.load("ensembleBaggedTreesExtendedStay_V1.so").
  • Write an R wrapper to call the C function using .C with the following syntax: .C("C_my_func", arg1, arg2).
Hope this resolves your query. Happy coding !

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

태그

질문:

2023년 8월 29일

답변:

2025년 1월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by