Adding quotes to a user input
4 ビュー (過去 30 日間)
古いコメントを表示
Is it possible to write some code that will add single quotations to a user input to make it into a string so that it can be used in a switch loop, etc.
For example:
method = input('linear or cubic? ');
switch(method)
case 'linear'
disp('Method is linear')
case 'cubic'
disp('Method is cubic')
end
The user here must type in 'linear' or 'cubic', is it possible to make it so they can just type in linear or cubic without quotes.
1 件のコメント
Jan
2011 年 9 月 30 日
You can find the solution also by: "help input". Using "help" and "doc" is a good idea whenever a problem with a specific command appears.
採用された回答
その他の回答 (3 件)
Wayne King
2011 年 9 月 30 日
Hi, You can just use the 's' option in input.
method = input('linear or cubic?\n','s');
switch(method)
case 'linear'
disp('Method is linear')
case 'cubic'
disp('Method is cubic')
end
0 件のコメント
Robert Cumming
2011 年 9 月 30 日
method = input('linear or cubic? ', 's');
will force the variable "method" to be a string.
0 件のコメント
Bashiru Bukari
2020 年 3 月 22 日
Hi you can try this...
method =input('linear or cubic:','s');
switch method
case{'linear'}
disp('method is linear');
case{'cubic'}
disp('method is cubic');
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!