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!