Help me with this loop. contains handles structure

1 回表示 (過去 30 日間)
Waboraro Olefile
Waboraro Olefile 2016 年 9 月 9 日
コメント済み: Waboraro Olefile 2016 年 9 月 11 日
i have 16 objects, with tag 'box1,box2,box3.....' What i want is for the loop to access each of the objects and alter its property, either Color or any other property. how do i do this within a loop.
rcolour is just a custom function you can ignore it
for i=1:16 bcolour=rcolour() handles.box(i).BackgroundColor=bcolour; end

採用された回答

Henry Giddens
Henry Giddens 2016 年 9 月 11 日
If you want to do it like this, you can access structure fields using strings by enclosing the string referring to the fieldname in brackets. For your case:
for i = 1:16
str = sprintf('box%d',i);
handles.(str).BackgroundColor = bcolor; %
end
  2 件のコメント
Waboraro Olefile
Waboraro Olefile 2016 年 9 月 11 日
Thanks... it worked
Waboraro Olefile
Waboraro Olefile 2016 年 9 月 11 日
Is there any other way you would recommend me to do it though? thanks in advance... "if you want to do it like this"

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by