Change Background colour between values

Hello everyone.
I'm building a script that follows the angle of a IMU (Inertial Measurement Unit) in real time.
In this script im using a GUI, which shows the angle in numbers on a big "edit text" field with a white background.
(gui looks like this):
I want this background to change to a green color when the value of the angle is between 14.1 and 14.9 and between 19.6 and 20.4.
if the value is outside the given values the background should have a red color.
right now, this is what my script looks like:
function pitchTB_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
Data = handles.pitchTB;
if Data(Data > 12.1 && Data < 12.9)
set(hObject,'BackgroundColor','green')
elseif Data(Data > 19.6 && Data < 20.4)
set(hObject,'BackgroundColor','green')
else
set(hObject,'BackgroundColor','red')
end
The code doesnt give me any errors, but it wont change the color of the background.
Does anyone know what im doing wrong?

 Respuesta aceptada

Romeo dean Van Burik
Romeo dean Van Burik el 5 de Ag. de 2022
Editada: Romeo dean Van Burik el 5 de Ag. de 2022
Found the problem. i was working in the create function, which means the script doesnt get updated while running the GUI.
i put it underneath the timer function, which led to the script working:
if (eulP < -12.1 && eulP > -12.9) || (eulP < -19.6 && eulP > -20.4)
set(handles.pitchTB,'BackgroundColor','green');
elseif eulP > -0.10 && eulP < 0.10
set(handles.pitchTB,'BackgroundColor','white');
else
set(handles.pitchTB,'BackgroundColor','red');
end

Más respuestas (1)

Image Analyst
Image Analyst el 29 de Jul. de 2022

0 votos

See attached demo that shows you how to change just about everything on your figure.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by