Right now I have name=input('What is the name of the planet?','s'); mass=input('What is the mass of %s?',name);
How do I insert the input of a string into an input asking for a number?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Kyle Reagan
el 9 de Mzo. de 2016
Comentada: Star Strider
el 9 de Mzo. de 2016
My example is naming a planet then asking for the mass of that specific planet in the next line. How do I call the name of the planet as a string into the second line?
Respuesta aceptada
Star Strider
el 9 de Mzo. de 2016
I prefer using the inputdlg funciton.
This works:
p_namec = inputdlg('What is the name of the planet? ');
p_massc = inputdlg(sprintf('What is the mass of %s? ', p_namec{:}));
p_mass = str2num(p_massc{:}); % Numeric Value
2 comentarios
Star Strider
el 9 de Mzo. de 2016
My pleasure!
Just use the input function:
p_name = input('What is the name of the planet? ', 's');
p_mass = input(sprintf('What is the mass of %s? ', p_name));
p_mass = p_mass; % Numeric Value
That should work.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!