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

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?

回答 (1 件)

Subhajyoti
Subhajyoti 2024 年 8 月 6 日
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.

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

製品

リリース

R2023b

質問済み:

2024 年 6 月 2 日

回答済み:

2024 年 8 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by