GUI: Change backround of "Edit text" box using if structure
Show older comments
Hello! In my GUI I have two inputs and output (they are "Edit text" boxes) and a button which executes a function. As I said, the final output goes to Edit Text box. I want to analyze this output with if structure, and, depending on the value, assign different background color for the box.
I tried using set(hObject,'BackgroundColor','color'), (example below) And it worked..
function box_CreateFcn(hObject, eventdata, handles)
set(hObject,'BackgroundColor','color')
But when it is inside IF structure, MATLAB returns many errors and code doesn't work (see code below)
function box_CreateFcn(hObject, eventdata, handles)
if value <-30
set(hObject,'BackgroundColor','blue');
elseif value>=-30
set(hObject,'BackgroundColor','grey');
elseif value<=100
set(hObject,'BackgroundColor','black');
else
set(hObject,'BackgroundColor','red');
end
What am I doing wrong? :)
1 Comment
Jan
on 26 Nov 2012
When ever you mention, that errors appear, it is a good idea to post the messages also.
Accepted Answer
More Answers (1)
Image Analyst
on 26 Nov 2012
Edited: Image Analyst
on 26 Nov 2012
0 votes
Have you tried to use the debugger? Set a breakpoint and see if it actually gets into any of the "if" conditions that you list.
And what is "value" - have you assigned that yet?
And you can try using handles.box instead of hObject.
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!