How to assign object to an array?

조회 수: 8 (최근 30일)
Umit
Umit 2012년 8월 5일
Let's assume I got an object called A() and an array called Array(5).class How can I assign all elements of class a new object of A().
Array(1:5).class = A()
Wont work. I don't want to use for loop;
for i=1:5
Array(i).class = A()
end
P.S: I want each element of array to assign a new A() object, not the same. A() is constructor of A also.

채택된 답변

Walter Roberson
Walter Roberson 2012년 8월 5일
In order to assign new A() objects, you will need to use a loop, or will need to write that many (e.g., 5) object references.
  댓글 수: 2
Umit
Umit 2012년 8월 5일
You say there is no way to do it except loop. Ok, I got it.
Walter Roberson
Walter Roberson 2012년 8월 5일
Yes, the methods that handle multiple assignment would assign the same object to each.

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

추가 답변 (0개)

카테고리

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