Is there a way to view/access all instances of a property?

조회 수: 4 (최근 30일)
Rachel Anthony
Rachel Anthony 2018년 7월 10일
편집: Sean de Wolski 2018년 7월 10일
I'm new to Matlab, and confused on how instances are stored. Say that I have a class outlining a couple properties:
properties
name = []
value = []
end
At each instance, an object defines the name/value properties differently. Is there a way to store/access all instances of each property?
For example, say I make a few different objects and define their properties (we'll call this class 'MyClass')
a = MyClass;
a.name = 'Var1';
a.value = [2 4];
b = MyClass;
b.name = 'Var2';
b.value = [4 6 8];
c = MyClass;
c.name = 'Var3';
c.value = [1 2 3 4];
Say I want to access all instances of the property 'value'. How would I get something like this as the output?
value = [[2 4], [4 6 8], [1 2 3 4]];
My bad if this is worded poorly!

채택된 답변

Sean de Wolski
Sean de Wolski 2018년 7월 10일
편집: Sean de Wolski 2018년 7월 10일
Rather than a, b, and c.; create a 3x1 object array
a(1).name = 2
a(2).name = 3
a(3).name = 4
Then just
{a.name}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by