- https://www.mathworks.com/help/coder/gs/generating-c-code-from-matlab-code-using-the-matlab-coder-project-interface.html
- https://www.mathworks.com/matlabcentral/answers/452267-can-i-generate-dlls-using-matlab-coder
Issues with Converting Binary Array to Decimal Value in MATLAB DLL for C++ Integration
4 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Subhajyoti
on 6 Aug 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.
0 Comments
See Also
Categories
Find more on MATLAB Compiler SDK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!