MATLAB Answers

Help me with this loop. contains handles structure

1 view (last 30 days)
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(); end

Accepted Answer

Henry Giddens
Henry Giddens on 11 Sep 2016
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; %
Waboraro Olefile
Waboraro Olefile on 11 Sep 2016
Is there any other way you would recommend me to do it though? thanks in advance... "if you want to do it like this"

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by