Is there a simple way to set a property of multiple (potentially different) objects in a cell array?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Fangjun Jiang
2016-2-12
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!