Indexing into Structures

Hi,
I currently have an array of structures that have fields whose values are also arrays. I am trying to grab one column of data from every single structure in matlab...
the statement I use to do this is the following
structName(:).fieldName(:,1)
However this isn't grabbing the first column of the value fieldName from ALL structures. I'm only getting a single array of data and not the twenty that I should normally be getting, because there are twenty structures.
Am I missing something here or is this a limitation of Matlab?

 Accepted Answer

Walter Roberson
Walter Roberson on 17 Jan 2012

0 votes

Are all of fieldName the same size? Do they all have the same number of rows? If so then there some simplifications that can be made.
To give an answer, though, we need to know what output datatype and shape you are looking for.

4 Comments

Daniel
Daniel on 18 Jan 2012
Walter,
What I'm looking for in my final answer is a 20x51 array.
Each value of 'fieldName' is a 20X51 array of doubles. What I want to do is take the first column in each 'fieldName' and create a new array for my final answer
I've made sure it's not a transpose issue, but am at a loss for why it's not working. Perhaps I need to use a for loop?
Daniel
Daniel on 18 Jan 2012
bump
Each value in fieldName is 20x51, and you want to take the first column of each, so that would be 20x1 for each. You want the result to be 20x51. Is the implication that your structure array has 51 elements and you want the second dimension index to be the same as the structure array index? Or is the 20x51 desired result somehow related to the fact that each fieldName is 20x51, even though you only want the first column of each fieldName ?
Daniel
Daniel on 19 Jan 2012
I'm sorry I mean rows NOT columns which would then achieve the 20x51 array... anyway...I've figured out the solution and it had to do with multilevel indexing that matlab does not allow you to do.
You must convert the structures to a cell array and then operate that way. Thank you for your help though. Much appreciated.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!