Got Questions? Get Answers.
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:
How do I easily view type info of structure fields?

Subject: How do I easily view type info of structure fields?

From: Michael

Date: 2 Sep, 2010 17:11:22

Message: 1 of 2

Hi,

How do I see the types of structure fields?

Let's say I do this:

  st.n = 1;
  st.s = 'hi';

Typing 'whos st' yields

  st 1x1 524 struct

But 'whos st.n' yields nothing.

Typing just 'st' shows me the fields and their values.
I'd like to show the fields and their types and sizes in the way whos does for numeric types. I could write a routine to iterate through and do this, but it seems this would be a common function, but I can't find anything. Thanks for any help!

Cheers,
Michael

Subject: How do I easily view type info of structure fields?

From: Walter Roberson

Date: 2 Sep, 2010 17:20:40

Message: 2 of 2

On 02/09/10 12:11 PM, Michael wrote:

> How do I see the types of structure fields?
> Let's say I do this:
>
> st.n = 1;
> st.s = 'hi';
>
> Typing 'whos st' yields
>
> st 1x1 524 struct
> But 'whos st.n' yields nothing.
>
> Typing just 'st' shows me the fields and their values.
> I'd like to show the fields and their types and sizes in the way whos
> does for numeric types. I could write a routine to iterate through and
> do this, but it seems this would be a common function, but I can't find
> anything. Thanks for any help!

Recall that a structure is really a structure _array_, and that there is
nothing that requires that the field types and sizes be the same in each
of the array members. For example,

st.n = uint8(1);
st.s = 'hi';
st(2).n = pi;
st(2).s = struct('flower', rand(3,20));

st(1).n is a different size and type than st(2).n and st(1).s is
completely different than st(2).s . st(2).s.flower will exist but
st(1).s.flower will not exist.

Thus in order to implement such a tool, it would have to step through
all of the structure elements and analyze them individually: there is no
meaningful answer for an entire structure.

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