필터 지우기
필터 지우기

Help me with this loop. contains handles structure

조회 수: 2 (최근 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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by