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!