0

I need to access to a structure that is inside a structure: I have a main structure called GlobalStruc that has many items (my "packets"). Each packets contains many info, i.e. has many fields. One of which is itself a structure with several fields. I need to have access to each of these fields. Any idea?

To sum up: GlobalStruc.DetailsStruc which contains many fields and has many indexes. How can I have access to these? If more convinient, can I create an array with these fields? Something like CharacteristicOfThePacket = GlobalStruc(index).DetailsStruc.FieldThatIWant

Here is an example of how the main structure was built: `

GlobalStruc(1).data1 = 1; GlobalStruc(1).data2 = 12; GlobalStruc(1).moredata.velocity = 327; GlobalStruc(1).moredata.bbeta = 3.2; GlobalStruc(2).data1 = 23; GlobalStruc(2).data2 = 56; GlobalStruc(2).moredata.velocity = 442; GlobalStruc(2).moredata.bbeta = 1.7; GlobalStruc(3).data1 = 4.3; GlobalStruc(3).data2 = 7; GlobalStruc(3).moredata.velocity = 556; GlobalStruc(3).moredata.bbeta = 1.1;

` Now I wish I could say:

myVelocities=GlobalStruc(:).moredata.velocity;

But I get this error :

Expected one output from a curly brace or dot indexing expression,
but there were 3 results.

Thank you so much,

1

1 Answer 1

0

You cannot in a single line, but you can do:

InnerStruct = [GlobalStruc.moredata];

Then access the first element:

InnerStruct(1)

ans = 

    velocity: 327
    bbeta: 3.2000

or the ith element of the structure:

InnerStruct(i)
Sign up to request clarification or add additional context in comments.

2 Comments

The thing is that I have many indexes in the main structure, and they share the same fields (name)... I updated my post ;) thank you for your help.
What if I need to assign the velocity of the with element to a vector A? This is actually my question ;) Thank you for your help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.