how to change datatype of libpointer

7 次查看(过去 30 天)
Hi , I am trying to use Matlab and shared library.
If I have a C function which is like below
void * foo(int n);
It's just like that we get a void type pointer containing n int data , returned from foo .
In C , we can change void type to int or double easily.
But how to change type in Matlab ?
I tried
pointer = calllib(lib,'foo',1000);
pointer.datatype = 'uint16Ptr'; %Changing the 'DataType' property of lib.pointer is not allowed.

采纳的回答

Guillaume
Guillaume 2016-3-1
编辑:Guillaume 2016-3-1
setdatatype(pointer, 'uint16Ptr', n); %assuming the pointer points to an array of n uint16
should work.
  2 个评论
Kev Chen
Kev Chen 2016-3-2
Thanks you .
I never thought that...
It works.
vishal sp
vishal sp 2022-5-6
iam getting error for this, Check for missing argument or incorrect argument data type in call to
function 'setdatatype'.
Error in getLineColour (line 14)
setdatatype(image,'uint8Ptr',3);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call C from MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by