How to define a pointer to an array of complex numbers ?
Show older comments
I have created an array of 10 complex numbers and initialized all elements to (1.0 +1.0i). I would like to define a pointer to the array "complex_array" inorder to pass that as an input argument to a c function. The function in the shared library has "_Complex float * v" as the argument type, which has been converted to "s_C_float_complexPtr" by the matlab loadlibrary(). Can this be achieved using libpointer() ? If yes, what is the type of the pointer ? Or is there any other way ?
array = zeros(1, 10, 'single');
complex_array = complex(complex(array, single(1.0)) + single(1.0));
dataptr = libpointer('s_C_float_complexPtr', complex_array);
calllib('lib','cmplx_mean_removal', dataptr, 10);
The above code throws the following error,
A structure is required.
Error in libpointer (line 21)
ptr=lib.pointer(varargin{:});
Note:
- Here is the content of ‘complex_array’ when I print it,
complex_array =
1×10 single row vector
Columns 1 through 8
1.0000 + 1.0000i 1.0000 + 1.0000i 1.0000 + 1.0000i 1.0000 + 1.0000i 1.0000 + 1.0000i 1.0000 + 1.0000i 1.0000 + 1.0000i 1.0000 + 1.0000i
Columns 9 through 10
1.0000 + 1.0000i 1.0000 + 1.0000i
2. Here is the signature of the c function, (uses standard complex notation from “complex.h”)
void cmplx_mean_removal( _Complex float * v, uint32_t len);
Would appreciate any inputs. Thank you.
1 Comment
Jerome Almon
on 4 Dec 2023
Edited: Jerome Almon
on 4 Dec 2023
Accepted Answer
More Answers (0)
Categories
Find more on Dates and Time 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!