Problem using array in MATLAB with external library from DLL
4 次查看(过去 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 中查找有关 Call C from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!