Beginner... why a matrix with numbers and strings doesn't give me the numbers? ( I know I have to transform the numbers into strings)

1 回表示 (過去 30 日間)
I just would like to know how it works.
e.g
t = 71 ;
c = (t-32)/1.8 ;
hey = ['The temperature is , c , 'C']
  1. it's not going to work! I have to use a command to transform "c".why???
a = [ 'how's it going' , 10 , 'cool' ]
it will give me both strings but not the number 10 ....
it looks like there's no "10" in "a" ..
thanks for helping

採用された回答

Walter Roberson
Walter Roberson 2014 年 3 月 23 日
a = [ 'how''s it going' , num2str(10) , 'cool' ];
or
a = sprintf('how''s it going %d cool' 10];
or
a = sprintf('%s %d %s', 'how''s it going', 10, 'cool' ];
  3 件のコメント
Walter Roberson
Walter Roberson 2014 年 3 月 24 日
Characters are stored internally as non-negative integers, together with a flag indicating to display as characters. For example 33 corresponds to the character '1', 65 corresponds to 'A', 126 corresponds to '~'. When you mix numbers into a character array, the result might the flag saying to display as characters, or the flag might apply to the numbers as well. The number 10 corresponds to the character "newline" so mixing a 10 in with a string can result in a string that has newline at that location.
See also char()
Douglas Alves
Douglas Alves 2014 年 3 月 29 日
Thank you very much. That's exactly what I would like to know.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by