Working in MATLAB CODER with arrays using after calllib and DLL library. Wrong output

5 ビュー (過去 30 日間)
Bob
Bob 2022 年 7 月 7 日
回答済み: Harsh 2025 年 1 月 23 日
For instanse, I write some func, like this:
function out = test(in1,in2)
out = in1+in2;
end
Size of inputs in1 and in2 is double 1x2. When I go to MATLAB CODER and generate DLL library. I call these functions:
loadlibrary('test.dll','test.h')
out = calllib('test','test',[1 2],[3 4])
Ouput of this file is only double 1x1. How it can be?

回答 (1 件)

Harsh
Harsh 2025 年 1 月 23 日
Hi Bob,
While using MATLAB coder to generate dynamic library (DLL), the input parameter dimensions need to be specified correctly. When you run the MATLAB coder app it asks you to define input types. You can enter a script that calls the “test” function here and MATLAB coder will define the input types for you. Check the snapshot below to understand how you can achieve this -
Also, while calling the “test” function you need to pass the output pointer also with pre-allocated space for 1x2 output. Check the code below to understand how to achieve this -
% Define input data
in1 = [1 2];
in2 = [3 4];
out = libpointer('doublePtr', zeros(1, 2)); % Allocate space for 1x2 output
% Call the function
calllib('test', 'test', in1, in2, out);
% Display the result
disp(out.value);

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by