get_choice v2.3

버전 1.0.0.0 (2.39 KB) 작성자: Phillip M. Feldman
allow user to choose among alternatives by typing one of several short strings
다운로드 수: 1.8K
업데이트 날짜: 2008/5/12

라이선스 보기

% get_choice displays a prompt, reads a response (string) from standard
% input, trims trailing blanks, converts to lower case, and compares the
% result against strings in the "responses" cell array. If the response
% matches an entry in the cell array, the index of the first matching
% entry is returned. If the user types 'quit' or 'exit', the program is
% stopped. If the user input does not match any of these conditions, an
% error message is generated and the prompt is displayed again.
%
% Notes:
%
% 1. To implement a default response, the calling program must include a
% null string ('') as one of the entries in the responses cell array.
%
% 2. To implement multiple versions of any given response, the calling
% program should use nested cell arrays (see the example below).
%
% Example:
%
% choice= get_choice('Do you want to continue? ', ...
% {{'n','no'},{'y','yes'},'maybe'});
%
% The above call returns 1 if the user enters 'n' or 'no', 2 if the user
% enters 'y' or 'yes', and 3 if the user enters 'maybe'.

% Revision History

% Version 2.3, 7 May, 2008

% Modified code to perform case-insensitive string comparisons rather than
% converting input to lower case. The main reason for this change is that
% the 'extra' string may contain the name of a workspace variable, in which
% case upper/lower case must be preserved.

인용 양식

Phillip M. Feldman (2024). get_choice v2.3 (https://www.mathworks.com/matlabcentral/fileexchange/19879-get_choice-v2-3), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2008a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0