- person is the array of objects
- person has a property named, 'eye', the value of which is an eye-object
How to access sub-properties from an object array?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
So I have an array of objects and I ideally want to return an array of sub-properties two layers deep (if that makes sense). For example, I would like:
array=person.eye.color
to return all of the person eye colors into one array. I can return an array of eye objects but not the eye colors themselves.
I get the error: "Expected one output from a curly brace or dot indexing expression, but there were 3 results."
I'm not a very experienced programmer or very familiar with Matlab's structure, any advice? Thanks.
0 comentarios
Respuestas (1)
per isakson
el 27 de Oct. de 2018
Assuptions
Answer
There is no one-liner that does what you want. You have to loop over all persons of the array.
2 comentarios
Walter Roberson
el 27 de Oct. de 2018
array = arrayfun(@(P) P.eye.color, person); %hidden loop
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!