How to convert C struct from mxArray pointer of structs?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sabyrzhan Tasbolatov
el 7 de Ag. de 2022
Comentada: Sabyrzhan Tasbolatov
el 8 de Ag. de 2022
If I have in C file
struct FooInner {
double Bar;
int32 Baz;
};
struct Foo {
struct FooInner inner;
....
};
which is called via Matlab SDK C Compiler with following code:
if (mlxDo_smth_api(n_out, out, n_in, in))
{
mxArray *fooArrPtr = mxGetData(out[0]);
for (int i = 0; i < 100; i++)
{
struct FooInner *fooInnerPtr = (struct FooInner *) mxGetPr(fooArrPtr);
printf("Bar = %f, baz = %d\n", fooInnerPtr->Bar, fooInnerPtr->Baz);
}
}
then I'm getting random numbers. I know how to parse a single struct fields from Matlab (need to mxGetData and cast it to proper struct field data type), however, how to do with array of structs? I can't increment fooArrPtr as well -- giving me error that I can't increment mxArray.
2 comentarios
James Tursa
el 8 de Ag. de 2022
Editada: James Tursa
el 8 de Ag. de 2022
Where is out[0] coming from? Unless you have something very strange going on, it looks like you are mixing mxArray struct types with native C struct types, which I wouldn't expect to work. That is, the result of the mxGetData(out[0]) might be an mxArray pointer if out[0] is a an mxArray cell or struct, but then the result of the mxGetPr(fooArrPtr) call I would definitely not expect to be a native C struct type. Hence my question.
Respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Compiler en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!