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)
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.

Réponses (1)

Fangjun Jiang
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?
  1 commentaire
Matthew Eicholtz
Matthew Eicholtz le 12 Fév 2016
I think the array approach will only work if all objects are of the same class, which is not always the case for me.

Connectez-vous pour commenter.

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!

Translated by