Mercurial > repos > public > sbplib
annotate yesnoQuestion.m @ 1223:9fddc8749445 rv_diffOp_test
Closing branch
| author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
|---|---|
| date | Mon, 05 Aug 2019 10:48:37 +0200 |
| parents | 0c166d195f58 |
| children |
| rev | line source |
|---|---|
|
10
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
1 function b = yesnoQuestion(question, defaultAnswer) |
|
11
0c166d195f58
Allowed no defult answer in yesnoQuestion.m
Jonatan Werpers <jonatan@werpers.com>
parents:
10
diff
changeset
|
2 default_arg('defaultAnswer','nodefault'); |
|
10
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
3 |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
4 yesAnswer = {'y','Y','yes','Yes','YES'}; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
5 noAnswer = {'n','N','no','No','NO'}; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
6 |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
7 switch defaultAnswer |
|
11
0c166d195f58
Allowed no defult answer in yesnoQuestion.m
Jonatan Werpers <jonatan@werpers.com>
parents:
10
diff
changeset
|
8 case 'nodefault' |
|
0c166d195f58
Allowed no defult answer in yesnoQuestion.m
Jonatan Werpers <jonatan@werpers.com>
parents:
10
diff
changeset
|
9 optionString = '[y/n]'; |
|
10
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
10 case yesAnswer |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
11 optionString = '[Y/n]'; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
12 yesAnswer{end+1} = ''; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
13 case noAnswer |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
14 optionString = '[y/N]'; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
15 noAnswer{end+1} = ''; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
16 otherwise |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
17 error('Unrecognized default answer: %s', defaultAnswer); |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
18 end |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
19 |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
20 b = []; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
21 while isempty(b) |
|
11
0c166d195f58
Allowed no defult answer in yesnoQuestion.m
Jonatan Werpers <jonatan@werpers.com>
parents:
10
diff
changeset
|
22 answer = input([question ' ' optionString ': '],'s'); |
|
10
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
23 switch answer |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
24 case yesAnswer |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
25 b = true; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
26 case noAnswer |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
27 b = false; |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
28 end |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
29 end |
|
9551f4e7cb66
Added utility function for asking the user a yes or no question.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
30 end |
