How can I assign a logical state to a led colour

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

Respuestas (2)

Ryan G
Ryan G el 2 de Oct. de 2012
Editada: Ryan G el 2 de Oct. de 2012
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 comentarios

Marco
Marco el 2 de Oct. de 2012
I thought about that but...I prefer to use something "directly connected" to the logic state rather to creare a condition according to variable state. I hope you understand. However thanks!
Image Analyst
Image Analyst el 2 de Oct. de 2012
Maybe you can try linkprop() or linkaxes().
Ryan G
Ryan G el 2 de Oct. de 2012
logicalState = 1;
set(led,'BackgroundColor',[logicalState ~logicalState 0]);

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 2 de Oct. de 2012

0 votos

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).

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 2 de Oct. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by