如何使用以前的用户输入并将其放入另一个用户输入语句?

时间:2015-10-29 06:08:48

标签: string matlab input string-formatting user-input

a = input('What is the name of the exoplanet? ','s');

mass = input('What is the mass of %s (kg)? ', a)

radius = input('What is the estimated radius of %s (km)? ', a)

masssp = input('What is the mass of the specimen (kg) ')

newton = (mass * radius)/masssp

fprintf('On %s , it would weight approxomately %d Newtons ', s, newton)

1 个答案:

答案 0 :(得分:0)

你的文字需要sprintf

a = input('What is the name of the exoplanet? ','s');
mass   = str2num(input(sprintf('What is the mass of %s (kg)?', a),'s'));
radius = str2num(input(sprintf('What is the estimated radius of %s (km)?', a),'s')) ;

然后将您的字符串转换为数字,否则您无法使用它进行计算...