Is there a simple way to set a property of multiple (potentially different) objects in a cell array?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Fangjun Jiang
le 12 Fév 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?
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!