Getting out of while loop when user says end

4 ビュー (過去 30 日間)
Carolyn
Carolyn 2019 年 7 月 16 日
コメント済み: Carolyn 2019 年 7 月 16 日
I have an image I am taking basic two point measurements on. The user is asked if they want to make another measurement and has the option of 'Yes', 'No', 'Cancel'. They can take as many or as few measurements as they want. I want to start this up if the answer is 'Yes' and re-ask the question after every measurement and keep looping until the answer is 'No' or 'Cancel'. This is what i have:
answer = questdlg('Do you want to make another measurement?');
while answer == 'Yes'
imshow(image)
[x,y] = getpts();
measurement = pdist([x.';y.']);
close
answer = questdlg('Do you want to make another measurement?');
end
But I get an error the 'Matrix dimensions must agree'. I'm assuming that the way I'm looping is incorrect. Can anyone see the problem with the loop? It only gives an error when I select 'No' or 'Cancel'.

採用された回答

Fangjun Jiang
Fangjun Jiang 2019 年 7 月 16 日
Use isequal(answer,'Yes') or strcmp(answer,'Yes')
'Yes'=='No' will cause the problem.
  1 件のコメント
Carolyn
Carolyn 2019 年 7 月 16 日
Thanks!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 7 月 16 日
With r2017a or later you can also use
answer == "Yes"

カテゴリ

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