Array of user defined types with external libraries
10 ビュー (過去 30 日間)
古いコメントを表示
Hi
I have a struct defined in my external c-library, e.g. :
struct MyStruct
{
char a;
short b;
}
Then I want to pass an array of these structs to my function
function myFunction1(struct MyStruct* str,int sz)
{
int kk;
for(kk=0;kk<sz;kk++)
{
str[kk].a = 1;
...
}
}
How can I do this using libpointer and libstruct? Can one only use arrays of basix types?
Thank you for any help! Thor Andreas
0 件のコメント
採用された回答
Philip Borghesani
2012 年 12 月 17 日
If you have at least R2009a then there is limited support for arrays of structures. Create a matlab structure array first then create a 'lib' object from it. This code shows how you can create and index into an array of structures in MATLAB. You should be able to pass either the created libstruct or the pointer to it to your function.
fileroot=fullfile(matlabroot,'extern','examples','shrlib','shrlibsample');
loadlibrary([fileroot,'.',mexext],[fileroot,'.h'])
ms(1).p1=1.1;
ms(2).p1=1.2;
ms(1).p2=2.1;
ms(2).p2=2.2;
ls=libstruct('c_struct',ms);
pls=libpointer('c_struct',ls); % OR pls=libpointer('c_struct',ms)
pls2=pls+1;
pls2.value
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
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!