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)
您的文本需要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')) ;
然后将字符串转换为数字,否则无法使用它进行计算…