Clear Filters
Clear Filters

How to get the array pointed by a double pointer in MATLAB?

27 views (last 30 days)
I'm trying to run an IBIS_AMI model in MATLAB. I have the dll library and head filer and I want to call function AMI_Init() in MATLAB.
The input of AMI_Init() is a double pointer that points to an impulse response, and is supposed to modify this impulse response in place.
I have an impulse response and I create a pointer with
ImpulseResponse_Ptr = libpointer('doublePtr',ImpulseResponse);
where ImpulseResponse is a 1024x1 double array.
The rest of the arguments passed to the functions are also created: (They are some parameters and are not so important)
Parameter_In = '(Trimode16_Tx (Model_Specific (tx_back_channel_calculation (Usage In)(Range 0 0 0)(Type Integer)(Default 0) (tx_vpp (Usage InOut)(Range 1.00 0.85 1.2)(Type Float)(Default 1.00)) (c1 (Usage InOut)(Range 0 -24 0)(Type Integer)(Default 0)) (c2 (Usage InOut)(Range 64 32 64)(Type Integer)(Default 64) )(c3 (Usage InOut)(Range 0 -24 0)(Type Integer)(Default 0))) ) ';
>> Parameter_Out = '(Trimode16_Tx (Model_Specific (tx_vpp (Usage InOut)(Range 1.00 0.85 1.2)(Type Float)(Default 1.00)) (c1 (Usage InOut)(Range 0 -24 0)(Type Integer)(Default 0)) (c2 (Usage InOut)(Range 64 32 64)(Type Integer)(Default 64) )(c3 (Usage InOut)(Range 0 -24 0)(Type Integer)(Default 0))) ) ';
>> row_size = 1024;
>> aggressors = 0;
>> sample_interval = 2.5E-11;
>> bit_time = 2E-10;
AMI_parameter_in_ptr = libpointer('voidPtr',[int8(Parameter_In) 0]);
>> vp = libpointer('voidPtr',[int8(Parameter_Out) 0]);
>> AMI_parameter_out_ptr = libpointer('voidPtrPtr',vp);
>> AMI_memory_handle = libpointer('voidPtr',0);
>> AMI_memory_handle_ptr = libpointer('voidPtrPtr',AMI_memory_handle);
>> msg = '';
>> msg = libpointer('voidPtr',[int8(msg) 0]);
>> msg_ptr = libpointer('voidPtrPtr',msg);
And then I call the function in the dll by:
calllib('Trimode16_AMI_Tx64','AMI_Init',ImpulseResponse_Ptr,row_size,aggressors,sample_interval,bit_time,AMI_parameter_in_ptr,AMI_parameter_out_ptr,AMI_memory_handle_ptr,msg_ptr)
And the return value is 1, which implies that the function was called successfully.
But I checked the array ImpulseResponse and it was the same as it was, so I am wondering if the modifed ImpulseResponse was stored somewhere else and pointed by the pointer ImpulseResponse_Ptr? If so, how to get the array pointed by a libpointer in MATLAB? Or is this not the problem?
First time to use a C shared library in MATLAB. I know there's a IBIS-AMI model in MATLAB but I'm trying to implement things on my own. Any hint would help.

Accepted Answer

Ashutosh
Ashutosh on 16 Aug 2023
In MATLAB, when you pass a pointer using "libpointer", any modifications made to the pointed data inside the function will not be automatically reflected in the original MATLAB variable. Instead, the modifications will be made to the memory location pointed by the pointer.
To get the modified data after you have called your update function is by using the "Value" property of the "libpointer" object. This property will allow you to access the data of the pointer.
Refer to the following link of the documentation to have more information about the "libpointer":

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!