How can I assign a logical state to a led colour

조회 수: 2 (최근 30일)
Marco
Marco 2012년 10월 2일
Hi,
I've a logical variable and I create a GUI with a pushbutton as a led
led = uicontrol('Style', 'pushbutton', 'Units', 'normalized', ...
'Position', [0.7 0.7 0.1 0.1], 'Selected', 'off', 'SelectionHighlight', 'on', 'Enable', 'on');
I need to change colour of the led as logical state.
I tried with an "if" and :
set(led, 'CData', cat(3,ones(64),zeros(64,64,2)));
but when logical state changes it doesn't follow the change
  댓글 수: 1
Daniel Shub
Daniel Shub 2012년 10월 2일
While not an exact duplicate, this is pretty close.

댓글을 달려면 로그인하십시오.

답변 (2개)

Ryan G
Ryan G 2012년 10월 2일
편집: Ryan G 2012년 10월 2일
Have you tried:
if true
set(led,'BackgroundColor',[1 0 0]) %set to red
else
set(led,'BackgroundColor',[0 1 0]) %set to green
end
  댓글 수: 3
Image Analyst
Image Analyst 2012년 10월 2일
Maybe you can try linkprop() or linkaxes().
Ryan G
Ryan G 2012년 10월 2일
logicalState = 1;
set(led,'BackgroundColor',[logicalState ~logicalState 0]);

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2012년 10월 2일
Why not have an axes, and you use image() or imshow() to display an actual photo of an LED, or a computer graphic image of an LED? I think that would look slicker than a colored pushbutton. I didn't even know pushbuttons could be colored - I thought that was a system setting (Control Panel).

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by