Integrating C code into MATLAB

Hi all,
I am struggling to merge a c code into matlab I have tried many methods but nothing seems to works. I have attached a copy of the c code along with its header files (it is a Battery management system) which run of an can bus. There are three outputs which are readings of the voltage across cell, temperature and the Module.
Thank you in advance :)

5 commentaires

Jan
Jan le 21 Mar 2022
Modifié(e) : Jan le 21 Mar 2022
It would be very useful, if you mention, which "many methods" you have tried so far and which problems occurred. This would avoid the waste of time to suggest on of these methods again.
Most likely all you need is a mex wrapper function, which converts the inputs from Matlab to c arrays. There is no useful documentation in the C code, so it is hard to guess, how the code should be used.
Jesvin Jose
Jesvin Jose le 21 Mar 2022
Hi Jan, Thank you for responding and apologies for the vague description. I tried using the Mex function and Matlab coder. The mex function seems the best option to integrate C code into MATLAB. But I am struggling with how to get the C code (along with the header files) implemented across.
Jan
Jan le 21 Mar 2022
You need to include a mexFunction as a wrapper between Matlab and C. There are several examples for such functions, which convert the Matlab arrays to C arrays. See <matlabroot>\extern\examples.
Jesvin Jose
Jesvin Jose le 21 Mar 2022
I want the C code array processed and stored in MATLAB. Would that be possible?
Jan
Jan le 21 Mar 2022
Yes, it is possible. The C code contains serveral function. It is not clear how they have to be called and what you want to export as output.

Connectez-vous pour commenter.

Réponses (1)

Kumar Pallav
Kumar Pallav le 23 Mar 2022

1 vote

Hi,
You can use 'coder.ceval' to call C/C++ function from MATLAB code. Please refer examples mentioned in this documenation for details.
Hope this helps!

Catégories

En savoir plus sur MATLAB Coder dans Centre d'aide et File Exchange

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by