Set size of array in object through input?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
i want to write a script with an object. One of the private properties should be an array. Its size should not be knew at the start of the script. During the run a function should ask the user to enter an integer. This integer should be the size of this 1D-array with the size.
How it could be implemented?
댓글 수: 0
채택된 답변
Guillaume
2018년 6월 28일
classdef SomeClass
properties (SetAccess = private)
Array = [];
end
methods
function this = SetArraySize(this)
sz = input('What size should the array be ? ');
validateattributes(sz, {'numeric'}, {'integer', 'positive', 'scalar'})
this.Array = zeros(1, sz);
end
end
end
%usage
obj = SomeClass %object with empty array
obj = obj.SetArraySize %prompts for array size
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cast and Quantize Data에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!