Execute multiple statements within an 'if' construct

조회 수: 4 (최근 30일)
Steven
Steven 2012년 4월 10일
I am trying to set properties of 3 textbox based on the state of a radiobutton. If the radiobutton is selected, I want the textboxes to be grayed so the user cannot enter values. My code works if I set only one textbox. However, I can't get it to change all of teh textboxes at the same time. Here is my code so far:
if (get(handles.radiobutton1 ,'Value') == get(handles.radiobutton1 ,'Max'))
set(handles.edit4,'Enable','off', 'BackgroundColor', 'gray')
set(handles.edit5,'Enable','off', 'BackgroundColor', 'gray')
set(handles.edit6,'Enable','off', 'BackgroundColor', 'gray')
else
set(handles.edit4,'Enable','on', 'BackgroundColor', 'white')
set(handles.edit5,'Enable','on', 'BackgroundColor', 'white')
set(handles.edit6,'Enable','on', 'BackgroundColor', 'white')
end
Is there a way to use "set" to apply to more than one function handle at a time? Or why I can't I have multiple statements within my "if"?
Thank you in advance!
  댓글 수: 1
Jan
Jan 2012년 4월 10일
You forgot to mention, which problem appears. Do you get an error message?

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

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 4월 10일
Use either RGB triplets (e.g. [1 0 0] for red) or one of the letters abbreviated in:
doc linespec
e.g. 'r' for 'red'
ps: gray using grb triplets will have all three (R,G,B) values the same:
e.g. 24 shades of gray:
gray(24)
  댓글 수: 2
Steven
Steven 2012년 4월 10일
Thanks Sean. [1 1 1] gets me gray!
Jan
Jan 2012년 4월 10일
[1, 1, 1] is white. If your uicontrol gets grey, this is an effect of setting the Enabled property.

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

추가 답변 (1개)

Jan
Jan 2012년 4월 10일
Actually this should work:
H = [handles.edit4, handles.edit5, handles.edit6];
if (get(handles.radiobutton1 ,'Value') == get(handles.radiobutton1 ,'Max'))
set(H, 'Enable','off', 'BackgroundColor', 'gray')
else
set(H, 'Enable','on', 'BackgroundColor', 'white')
end
But this has no substantial difference to your code. Therefore I assume, you get the same problem - what ever it might be.
  댓글 수: 2
Steven
Steven 2012년 4월 10일
Unfortunately, this behaves the same as my code above. I just read your question and looked at the error. The Matlab error had a lot of garbage in it, but it did say "Bad property value found". I changed the background color from gray to red and now it works?! However, the background color that displays is gray not red. Go figure. Any thoughts on this? Thanks for your help
Jan
Jan 2012년 4월 10일
No, the error message does not contain garbage. Experiences Matlab users understand the contents of the messages, therefore it is recommended to post the messages completely in this forum.

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

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by