2015-10-29 40 views
-4
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) 

回答

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')) ; 

,后来你的字符串转换为数字,否则你不能做的计算与它...

相关问题