Re: How to ask a user to select an option in Matlab? Thank You.
- From: Doug Schwarz <see@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 09 Sep 2005 00:16:14 GMT
In article <247F3373BB2C1CAC10A59892C1EA558A@xxxxxxxxxxxxxxxxxxx>,
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote:
> Hello,
>
> I am asking to the user to select an option:
>
> disp('1. Option 1');
> disp('2. Option 2');
> answer = input('Choose an option: ');
>
> I don't want anything to happen while the user doesn't choose 1 or 2.
> However I don't want to keep printing the text.
>
> Is this possible?
> How can I do this?
>
> I am using Matlab 7.04 SP2.
>
> Thank You,
> Miguel
This is a bit of a hack, but it might be what you want.
-----------------------------------------
function x = input_validate(prompt,valid)
backspace = sprintf('\b');
prompt_len = length(prompt);
while 1
x_str = input(prompt,'s');
x = str2num(x_str);
if ismember(x,valid)
break
end
num_bs = prompt_len + length(x_str) + 1;
fprintf(repmat(backspace,[1 num_bs]))
end
-----------------------------------------
Pass in your prompt and a vector of valid answers:
answer = input_validate('Choose an option: ', [1 2]);
--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.
.
- Follow-Ups:
- References:
- Prev by Date: Frame-based vs. sample-based simulink blocks
- Next by Date: Re: plotyy problem: two y1 limits overlaid
- Previous by thread: Re: How to ask a user to select an option in Matlab? Thank You.
- Next by thread: Re: How to ask a user to select an option in Matla
- Index(es):
Relevant Pages
|