Adding quotes to a user input
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Peter
el 30 de Sept. de 2011
Respondida: Bashiru Bukari
el 22 de Mzo. de 2020
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 comentario
Jan
el 30 de Sept. de 2011
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.
Respuesta aceptada
Daniel Shub
el 30 de Sept. de 2011
Try the 's' option.
method = input('linear or cubic? ', 's');
0 comentarios
Más respuestas (3)
Wayne King
el 30 de Sept. de 2011
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 comentarios
Robert Cumming
el 30 de Sept. de 2011
method = input('linear or cubic? ', 's');
will force the variable "method" to be a string.
0 comentarios
Bashiru Bukari
el 22 de Mzo. de 2020
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 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!