フィルターのクリア

How do I insert the input of a string into an input asking for a number?

2 ビュー (過去 30 日間)
Kyle Reagan
Kyle Reagan 2016 年 3 月 9 日
コメント済み: Star Strider 2016 年 3 月 9 日
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?
  1 件のコメント
Kyle Reagan
Kyle Reagan 2016 年 3 月 9 日
Right now I have name=input('What is the name of the planet?','s'); mass=input('What is the mass of %s?',name);

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 3 月 9 日
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 件のコメント
Kyle Reagan
Kyle Reagan 2016 年 3 月 9 日
Thank you! Is there a way to do it without the dialog boxes popping up? Like how the normal input function lets you type right next to it.
Star Strider
Star Strider 2016 年 3 月 9 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEarth and Planetary Science についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by