Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
structure array in mex file

Subject: structure array in mex file

From: Toan Cao

Date: 27 Aug, 2013 20:44:08

Message: 1 of 5

Hi,
I am writing a mex file where one of inputs is structure array. The structure array is a 1xN array in which each element is a structure and each structure has M fields.
In mex file, i want to know number of elements (N) of this structure array. Which function should i use ?
If i would like to access a field of each element , what should i do ?
Can you give me some suggestions? An detailed explanation will be appreciated!!!
I am looking forward to your reply!
Thanks in advance!

Toan

Subject: structure array in mex file

From: Phil Goddard

Date: 27 Aug, 2013 21:31:16

Message: 2 of 5

You need to use mxIsStruct (http://www.mathworks.com/help/matlab/apiref/mxisstruct.html) to check that you have been passed a structure, then functions like mxGetField and the other 8 methods listed below it at http://www.mathworks.com/help/matlab/access-data.html.

There are multiple examples linked off the above doc pages.

Phil.

Subject: structure array in mex file

From: Toan Cao

Date: 28 Aug, 2013 13:35:09

Message: 3 of 5

"Phil Goddard" <phil@goddardconsulting.ca> wrote in message <kvj5r4$e8$1@newscl01ah.mathworks.com>...
> You need to use mxIsStruct (http://www.mathworks.com/help/matlab/apiref/mxisstruct.html) to check that you have been passed a structure, then functions like mxGetField and the other 8 methods listed below it at http://www.mathworks.com/help/matlab/access-data.html.
>
> There are multiple examples linked off the above doc pages.
>
> Phil.

Thanks Phil, your suggestion is very useful for me!

Toan

Subject: structure array in mex file

From: Steven_Lord

Date: 28 Aug, 2013 14:07:41

Message: 4 of 5



"Phil Goddard" <phil@goddardconsulting.ca> wrote in message
news:kvj5r4$e8$1@newscl01ah.mathworks.com...
> You need to use mxIsStruct
> (http://www.mathworks.com/help/matlab/apiref/mxisstruct.html) to check
> that you have been passed a structure, then functions like mxGetField and
> the other 8 methods listed below it at
> http://www.mathworks.com/help/matlab/access-data.html.
>
> There are multiple examples linked off the above doc pages.

And since the OP indicated this is a nonscalar struct array,
mxGetNumberOfElements will reveal how many elements that struct array
actually has.

http://www.mathworks.com/help/matlab/apiref/mxgetnumberofelements.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: structure array in mex file

From: Toan Cao

Date: 28 Aug, 2013 15:02:08

Message: 5 of 5

"Phil Goddard" <phil@goddardconsulting.ca> wrote in message <kvj5r4$e8$1@newscl01ah.mathworks.com>...
> You need to use mxIsStruct (http://www.mathworks.com/help/matlab/apiref/mxisstruct.html) to check that you have been passed a structure, then functions like mxGetField and the other 8 methods listed below it at http://www.mathworks.com/help/matlab/access-data.html.
>
> There are multiple examples linked off the above doc pages.
>
> Phil.

Thanks Phil, your suggestion is very useful for me!

Toan

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us