Object array: modify properties of a single element
이전 댓글 표시
I'll try to be short.
I have the class "testClass" defined in this way:
classdef testClass<handle
properties
value=[];
end
methods
function modifyValue(input,number)
input.value=number;
end
end
end
Then, in the command window I write:
>>MyClass(1:10)=testClass;
>>MyClass(1).modifyValue(10);
The idea is to create an array of objects (made of, in this case, 10 elements). With the second line command I'd like to modify only the property ("value") of the first element of the array "MyClass", leaving the properties of the other elements "MyClass(2:end)" unchanged.
I get the following:
>> MyClass(1)
ans =
testClass with properties:
value: 10
>> MyClass(2)
ans =
testClass with properties:
value: 10
[...]
the property "value" is set equal to 10 for all the elements of the array "MyClass". How can make it work in the intended way? (e.g. "MyClass(1)" having a property "value" equal to 10 while "MyClass(2)" equal to [])
Thank you for your help and sorry for my bad english.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!