Is there a simple way to set a property of multiple (potentially different) objects in a cell array?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Suppose I have a cell array of objects (which may belong to different classes),
C{1} = [1x1 toolpack.component.TSLabel]
C{2} = [1x1 toolpack.component.TSButton]
...
C{n} = [1x1 toolpack.component.TSSlider]
but are assumed to contain a specific property (let's use 'Enabled' for this example).
isprop(C{ii},'Enabled') returns true for ii=1:n
How can I quickly set the desired property for all cells in the array? Obviously, I could use a for-loop
for ii=1:length(C)
C{ii}.Enabled = true; %or false
end
but I am curious if there is a way to do this without the for-loop.
0 Commenti
Risposte (1)
Fangjun Jiang
il 12 Feb 2016
This might be hard. cellfun() won't apply either. However, I know that if I have an array of the object handles, set(ArrayOfObjectHandle,'Enable',true) will work.
Any chance you might be able to store the object handle in an array, rather than the cell array of objects?
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements 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!