필터 지우기
필터 지우기

How to convert C struct from mxArray pointer of structs?

조회 수: 3 (최근 30일)
Sabyrzhan Tasbolatov
Sabyrzhan Tasbolatov 2022년 8월 7일
댓글: Sabyrzhan Tasbolatov 2022년 8월 8일
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
James Tursa
James Tursa 2022년 8월 8일
편집: James Tursa 2022년 8월 8일
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.
Sabyrzhan Tasbolatov
Sabyrzhan Tasbolatov 2022년 8월 8일
I'm gathering information from Matlab function like
function [output] = MyFunc(in1, in2)
..
output = struct('inner', {}, 'smth', {})
..
output{ii}.inner = inner_result
end
Thanks for pointing out not to mix mxArray with C struct. Will reformat to collect result into flatten array of values, rather than array of structs for output.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by