필터 지우기
필터 지우기

My Selection Dialog Box Contains Two Options, but only Displays one Image

조회 수: 2 (최근 30일)
shiffraw dagnechaw
shiffraw dagnechaw 2018년 8월 22일
댓글: Walter Roberson 2018년 8월 28일
I attached an image of my code. For some reason when I choose either option(subtraction or division) in the dialog box the same image appears. I'm not sure what's wrong with my code.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 8월 22일
Change
if 'Subtraction'
to
if length(indx) ~= 1
uiwait(msgbox('Must select exactly one choice'));
elseif strcmp(list1{indx}, 'Subtraction')
  댓글 수: 2
shiffraw dagnechaw
shiffraw dagnechaw 2018년 8월 28일
Thank you so much sir, it worked. I'm still trying to figure out why my simple code didn't work
Walter Roberson
Walter Roberson 2018년 8월 28일
Your existing code
if 'Subtraction'
does not compare the user input to anything. Instead, it is an example of if being applied to a vector of values. When you apply if to a vector of values, the if is considered to succeed if all of the values in the vector are numerically non-zero. 'S' and 'u' and 'b' and so on are not char(0), so all of the entries in the vector are indeed numerically non-zero, so the test was considered to always succeed.
Note: the character '0' is char(48), numerically 48, and so is non-zero. Only char(0), known formally as NUL, is considered to be numerically zero.

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

Community Treasure Hunt

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

Start Hunting!

Translated by