Problem using array in MATLAB with external library from DLL
조회 수: 7 (최근 30일)
이전 댓글 표시
I am using MATLAB to control Thorlabs software. I am having trouble with any of the functions from the imported library that need to return arrays. Here is an example of my code I am using and the description from the manual: my code:
waveType=libpointer('int32Ptr',0)
pupil=libpointer('int32Ptr',1)
arraywavefront=zeros(spotsy.value,spotsx.value,'uint16');
calllib('WFS_64','WFS_CalcWavefront',hdl.value,waveType,pupil, arraywavefront);
I am having trouble with the arraywavefront syntax. when I look at arraywavefront after calling this function, it is still a 2D array of all zeros. I have also tried:
array=zeros(spotsy.value,spotsx.value);
arraywavefront=libpointer('doublePtr',array)
which gives me the error "Error using calllib, Array must be numeric or logical"
For context, here are the parameters from the library:
WFS_CalcWavefront(instrumenthandle, ViInt32 waveType, ViInt32 pupil, float arrayWavefront[]);
for the arrayWavefront parameter:
float[], this parameter returns a 2D array of float containing the data
would love any help or insight anyone can offer! Hope this is enough context/code
댓글 수: 0
답변 (1개)
Manish Annappa
2017년 7월 12일
As I understand from your description, you want 'arraywavefront' to be modified by the shared library. According to the link below 'libpointer' is the correct function to be used for this scenario.
The prototype of the function 'WFS_CalcWavefront' shows that 'arrayWavefront' parameter is of float type. According to the link below, corresponding data type in MATLAB for C type 'float *' is 'singlePtr'. Make changes in 'libpointer' statement accordingly.
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!