how to pass array of structs from Matlab to external C library?

2 views (last 30 days)
I am able to successfully call functions in my external C library from Matlab. However, I do not know how to pass an array of structures from Matlab to my C library. The following illustrates what I want to do.
1) assume my C library has a structure defined as follows:
struct MyStruct { int X; int Y; }
2) an array of these structures is passed to a function on my C library. For example:
void MyFunction( struct MyStruct* ptr, int count )
{
for( int x = 0; x < count; ++x )
printf( "index %: x = %i, y = %i", x, ptr[x].X, ptr[x].Y );
}
3) In Matlab, I create an array of structures:
arrayOfStructures(1).X = 1;
arrayOfStructures(1).Y = 2;
arrayOfStructures(2).X = 3;
arrayOfStructures(2).Y = 4;
arrayOfStructures(3).X = 5;
arrayOfStructures(4).Y = 6;
4) My question is, how do I pass 'arrayOfStructures' to 'MyFunction' in my C library? I can successfully pass a single structure but not an array.
Thanks,
Ian

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!