Set size of array in object through input?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Michael Simonovski
il 28 Giu 2018
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 Commenti
Risposta accettata
Guillaume
il 28 Giu 2018
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Cast and Quantize Data in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!