Is there a simple way to set a property of multiple (potentially different) objects in a cell array?

2 views (last 30 days)
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.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 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?

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!