Dimension of fields in mwArray structs?

조회 수: 4 (최근 30일)
hnde
hnde 2011년 2월 10일
Hello,
I have a quesiton about the dimensions of the structs created by mwArray when the structs have fields.
For example,
const char *fields[] = {"field1", "field2"};
mwSize dims[2] = {2, 2};
mwArray m(2,dims, 2, fileds);
In this case, is field1 and field2 a 2x2 matrix?
What can I do if I want to have a mxn matrix in field1 and a jxk matrix in field2?
Thank you.

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2011년 2월 10일
I think what you're declaring is really a 2x2 matrix of structures with two fields: field1 and field2.
You could try the alternative syntax for mwArray:
const char *fields[] = {"field1", "field2"};
mwSize dims[2] = {1, 1};
mwArray m(2,dims, 2, fields);
mwArray field1(m, n, mxDOUBLE_CLASS);
mwArray field2(j, k, mxDOUBLE_CLASS);
m.Get(fields[0],1,1).Set(field1);
m.Get(fields[1],1,1).Set(field2);
  댓글 수: 2
hnde
hnde 2011년 2월 10일
Thank you very much for your answers. They helped me a lot.
I have another question, somewhat unrelated.
If in matlab and in C++, the struct 'm' which holds the fields field1 and filed2 are of type DataStruct, is there any way I can convert 'm' directly to mwArray type?
Right now I am just assigning the values to the fields seperately, and I was just wondering if it is possible to cast the DataStruct type to mwArray directly?
Thank you very much.
Kaustubha Govind
Kaustubha Govind 2011년 2월 16일
I think you do need to assign the values explicitly - I am not aware of a way to do this directly.

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

카테고리

Help CenterFile Exchange에서 Deploy to C++ Applications Using mwArray API (C++03)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by