【问题标题】:How do I use previous user input and put it into another user input statement?如何使用以前的用户输入并将其放入另一个用户输入语句中?
【发布时间】:2015-10-29 06:08:48
【问题描述】:
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)

【问题讨论】:

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


    【解决方案1】:

    你的文本需要 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')) ;
    

    然后将你的字符串转换为数字,否则你不能用它进行计算......

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 2021-05-27
      • 2018-04-29
      相关资源
      最近更新 更多