Help please (button click determination)
조회 수: 3 (최근 30일)
이전 댓글 표시
I have 100 buttons in my gui, and i want the gui determine which button is pressed (namely, which button callback is operated), is this possible? The main thing i want to do is to change the colour of the button which is clicked, among 100 buttons. I tried some commands, and came up to this code but here all button colours are changed, not a specific one, help please... here is the button callback:
for k=1:100
h = handlesStructure.(sprintf('button%d', k));
set(h, 'BackgroundColor',[1 0 0]);
end
Maybe there should be a totally different code, i don't know, help please!
댓글 수: 0
채택된 답변
Walter Roberson
2012년 3월 2일
Is this a uibuttongroup() collection, or is this a bunch of individual buttons?
If it is a bunch of individual buttons, then unless perhaps there is a method involving installing listeners, then the only callback that will be activated would be the callback for the individual button, whose callback would need to make the color change. The first parameter passed to the routine, usually called src, is the handle of the button that was activated.
curval = get(src,'Value');
maxval = get(src,'Max');
if curval == maxval
set(src, 'Color', [1.0 0.2 0.5]); %it is down
else
set(src, 'Color', [0.2 0.8 0.2]); %it is up
end
If you just want to be sure that "the current" button changes color, whatever the current button is, then the above kind of code will do it. If you care about identifying that (say) it was the "Morton Seasalt Blue #8" button specifically, then you may need more sophisticated coding.
댓글 수: 2
Walter Roberson
2012년 3월 2일
In GUIDE it would tend to be called hObject instead of src
http://www.mathworks.com/help/techdoc/creating_guis/f10-1000947.html
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!