Issues with Converting Binary Array to Decimal Value in MATLAB DLL for C++ Integration

4 visualizzazioni (ultimi 30 giorni)
Hello everyone,
I want to convert a binary array to a decimal value. When using MATLAB functions like bi2de and bit2int and then compiling them into a DLL using the library compiler, calling them from C++ results in errors indicating that the library could not be initialized. Is there an alternative MATLAB function that can be compiled into a DLL and called from C++ without issues?
I have also tried using a combination of bin2dec(num2str()), which loads the DLL correctly after compilation, but the execution results are incorrect. The result is displayed as a huge decimal number. What could be the reason for this?

Risposte (1)

Subhajyoti
Subhajyoti il 6 Ago 2024
Hi Alexander,
MATLAB Coder App can compile any MATLAB Function code into Dynamic Library (DLL) for dynamic linking to external projects.
You can use any built-in function or custom implementation within the primary MATLAB function to convert the binary array to a decimal value.
function decimalVal = convBinToDec(binVal) %#codegen
decimalVal = bin2dec(binVal);
end
Then, use the MATLAB Coder App to compile the MATLAB Function into DLL or any other build type and call the function.
Note: Set the Code Generation parameters appropriately according to your needs.
This approach should help you avoid issues with the built-in functions and allow you to call the MATLAB function from a C++ application successfully.
You may go through the following MathWorks documentation links to learn more about ‘Generate C Code by Using the MATLAB Coder App’:
I hope this helps.

Categorie

Scopri di più su C Shared Library Integration in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by