- 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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Compiler SDK 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!