필터 지우기
필터 지우기

How to store instances of an object property in a cell array?

조회 수: 33 (최근 30일)
Rachel Anthony
Rachel Anthony 2018년 7월 5일
댓글: Guillaume 2018년 7월 5일
I am making a class that defines a property 'Expression', which accepts vectors. Is there a way to access each instance of this property and store the vectors in a cell array? Thanks!
  댓글 수: 3
Rachel Anthony
Rachel Anthony 2018년 7월 5일
Thanks for your response, I'm new to Matlab so I'm still trying to better understand it, but that makes sense. To understand better what I'm trying to say: One object is created with the property 'Expression' set to [1:10], a second object is created with the property 'Expression' set to [2 4 6], and the last object is created with the property 'Expression' set to [5:10]. I'm trying to access each of these instances to compile them in a cell array. So, in this case the cell array would look like this:
expressionArray = {[1:10], [2 4 6], [5:10]};
Not sure if that is more clear but please let me know.
Guillaume
Guillaume 2018년 7월 5일
Then Matt guessed exactly what you wanted to do and has provided the answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2018년 7월 5일
편집: Matt J 2018년 7월 5일
If you have an array of such objects, then you can do
result={obj.Expression}
Or if you don't have an array, then build one first,
obj=[obj1,obj2,obj3];
result={obj.Expression};

추가 답변 (1개)

Wooshik Kim
Wooshik Kim 2018년 7월 5일
편집: Wooshik Kim 2018년 7월 5일
To add on to previous answer, add to your cell array as such
result = {obj1.Expression};
result{end+1} = obj2.Experssion;
result{end+1} = obj3.Expression;
...

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by