difference between x and 'x'

4 ビュー (過去 30 日間)
Mahmoud Elgarhy
Mahmoud Elgarhy 2019 年 11 月 26 日
回答済み: Mahmoud Elgarhy 2019 年 11 月 26 日
x= 0:5:20;
if x defined as above.what is the difference between x*2 and 'x'*2 ?
I got :
0 10 20 30 40 for x*2
and
240 for 'x' *2

採用された回答

Guillaume
Guillaume 2019 年 11 月 26 日
What a strange question!
x is the variable you previously defined, so x*2 multiply the content of the variable by 2.
'x' is a char vector that happens to contain the same letter that you used to name a variable but that's totally irrelevant. 'x'*2 multiply the character codes of the char vector by 2. The character code of the 'x' character is 120, so you get 240.
See for example:
>> 'hello'*2
ans =
208 202 216 216 222
because the character codes of 'h' is 104, 'e' is 101, 'l' is 108 and 'o' is 111.

その他の回答 (1 件)

Mahmoud Elgarhy
Mahmoud Elgarhy 2019 年 11 月 26 日
Guillaume, Thank you very much

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by