Display multiple output (integers and string) using fprintf

34 ビュー (過去 30 日間)
Kundera
Kundera 2017 年 6 月 8 日
コメント済み: Kundera 2017 年 6 月 8 日
Hi, I am trying to display something like '23 Celsius equal to 296,15 Kelvin' as the final output of a function that does this computation. In my script I have something like this:
A = T;
B = unitFrom;
C = result;
D = unitTo;
Where A is my input temperature (for example 23), B is 'Celsius', C is the converted temperature (in this example 296,15) e D is 'Kelvin'. I have a program where the user is asked to define A. B, and D and it will compute C. Finally, I would like to print the all conversion in a string like "'23 Celsius equal to 296,15 Kelvin'"
I have tried using fprintf but I didn't succeed.

採用された回答

Stephen23
Stephen23 2017 年 6 月 8 日
編集済み: Stephen23 2017 年 6 月 8 日
>> A = 23;
>> B = 'Celsius';
>> C = 296.15;
>> D = 'Kelvin';
>> str = sprintf('%.15g %s is equal to %.15g %s',A,B,C,D)
str = 23 Celsius is equal to 296.15 Kelvin
  1 件のコメント
Kundera
Kundera 2017 年 6 月 8 日
Thank you, I was using %d instead of %.15g

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by