Errors Within an If Statement
이전 댓글 표시
I keep getting these errors and I'm not sure why. Could somebody check it over and see where I'm exactly going wrong?
function questionsasked()
question1=questdlg('Are you ready to start?',...%question box
'Questions',...
'Yes','No','No');
question2=questdlg('Do you know the keys on the piano?',...
'Questions',...
'Yes','Somewhat','No','No');
question3=questdlg('How did you learn?',...
'Questions',...
'Self-Taught','Lessons','Other','Other')
question4=questdlg('How long did you take lessons for?',...
'Questions',...
'<1 year','1-10 years','>10 years','>10 years')
question5=questdlg('Are you still taking lessons?',...
'Questions',...
'Yes','No','No')
%user must click yes in order to continue
while ~strcmp(question1,'No')%<SM:WHILE>
if strcmp(question1,'Yes')
if strcmp(question2,'Yes')
if strcmp(question3,'Self-Taught')
else strcmp(question3, 'Lessons')
if strcmp(question4,'<1 Year')
if strcmp(question5,'Yes')
else strcmp(question5,'No')
end
else strcmp(question4,'1-10 year')
if strcmp(question5,'Yes')
else strcmp(question5,'No')
end
else strcmp(question4, '>10 years') %error
if strcmp(question5,'Yes')
else strcmp(question5,'No')
end
else strcmp(question3, 'Other')%error
else strcmp(question2,'No')%error
end
end
end
end
question1=questdlg('Are you ready to start?',...%question box
'Questions',...
'Yes','No','No');
end
댓글 수: 3
Rik
2020년 5월 1일
It looks like you think else is the same as elseif, it isn't. And what error are you getting exactly?
Han
2020년 5월 1일
Charleston Chan
2021년 7월 12일
There are 2 elses:
else strcmp(question3, 'Lessons')
else strcmp(question3, 'Other')%error
You need to change them to an elseif conditional
채택된 답변
추가 답변 (1개)
Hussein
2023년 8월 20일
0 개 추천
Please check one of these possible causes
Syntax errors Logical expression errors: Variable scope issues: Data type mismatches: Incorrect nesting or indentation: Typographical errors:
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!