My while loop is killing me...

8 ビュー (過去 30 日間)
Le Jepra
Le Jepra 2019 年 2 月 2 日
編集済み: Cris LaPierre 2019 年 2 月 2 日
Hi!
When the script finishes processing the data, it asks the user whether it should run again to process more data, or it should just end.
This should be a simple while loop, but somehow, I am struggling with it…
Here is my code:
repeatVar = 'yes';
while repeatVar == 'yes'
%data processing goes here
repeatVar = questdlg('Do you want to use this script to process another file?','Yes','No','No');
end
Where is the error?
Thanks!

採用された回答

Cris LaPierre
Cris LaPierre 2019 年 2 月 2 日
編集済み: Cris LaPierre 2019 年 2 月 2 日
Couple thoughts.
1. Your questdlg only displays a 'No' option. The 'Yes' is being interpretted as the title.
You want something more like
repeatVar = questdlg('Do you want to use this script to process another file?','Run Again','Yes','No','No');
2. Your button is 'Yes' (note the capitalization). Your while loop is comparing to 'yes' (again, note the capitalization). These are not equivalent, so your loop never repeats. When comparing text, it is better to use strcmpi (or related function).
while strcmpi(repeatVar,'yes')
  1 件のコメント
Le Jepra
Le Jepra 2019 年 2 月 2 日
Perfect!
Thank you very much!
Le

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by