Borrar filtros
Borrar filtros

How do I access properties of objects embedded inside another object organized in an array?

1 visualización (últimos 30 días)
I have created two classes, an 'inner' and 'outer' class. The 'outer' class has properties defined by methods that depend on data from the 'inner' class. I want to access properties for an array objects from the 'inner' class embedded inside an array of 'outer' class objects. I have tried indexing using various methods to no avail.
For example, I have 10 'outer' objects with 3 'inner' objects embedded within each. If I want to simultaneously define a value for a property of the array of 30 'inner' objects, I cannot. I have tried:
outer_obj(:,1).inner_obj(:,1).inner_property = value
but am getting an error. I haven't seen documentation that provides guidance on how to assign values to properties of an array of objects that are embedded inside an array.
Any assistance is greatly appreciated.
  2 comentarios
Geoff Hayes
Geoff Hayes el 29 de Mzo. de 2017
Please describe the error that you are observing. Copy and paste the full error message to your question (and the code that leads to the error).
per isakson
per isakson el 1 de Abr. de 2017
Editada: per isakson el 1 de Abr. de 2017
Is this the error message you see?
Expected one output from a curly brace or dot indexing expression,
but there were 2 results.
"I haven't seen documentation that provides guidance ... "
  • Why do you think it is possible?
  • What's not found in the documentation is typically not implemented!

Iniciar sesión para comentar.

Respuestas (1)

Iddo Weiner
Iddo Weiner el 1 de Abr. de 2017
% build an empty struct
A = struct;
A.outer = struct;
% either fill it
for i = 1:10
for j = 1:3
A(i,1).outer(j,1).inner = [i,j];
end
end
% or make it homogeneous
val = 'homogeneous input'
for i = 1:10;
for j = 1:3
A(i,1).outer(j,1).inner = val;
end
end

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by