フィルターのクリア

How do you multiply the letter "a" by 3?

45 ビュー (過去 30 日間)
Muhendisleksi
Muhendisleksi 2017 年 9 月 1 日
編集済み: Stephen23 2017 年 9 月 1 日
a =
'x'
>> a*3
Undefined operator '*' for input arguments of type 'cell'.
The result I want to achieve: 3*x
  5 件のコメント
the cyclist
the cyclist 2017 年 9 月 1 日
Stephen23
Stephen23 2017 年 9 月 1 日
編集済み: Stephen23 2017 年 9 月 1 日
Given
a = 'x'
and
>> a*3
Undefined operator '*' for input arguments of type 'cell'.
and the statement "The result I want to achieve: 3*x", what is x supposed to be? Is this a reference to something else?

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

回答 (4 件)

the cyclist
the cyclist 2017 年 9 月 1 日
編集済み: the cyclist 2017 年 9 月 1 日
If you have a character array and you want to replicate it, use repmat:
repmat('a',1,3)
  1 件のコメント
Muhendisleksi
Muhendisleksi 2017 年 9 月 1 日
no, like 3a.

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


the cyclist
the cyclist 2017 年 9 月 1 日
If you are trying to multiply a symbolic variable, then you should just be able to use mtimes as you have done. But why is your symbolic in a cell array?

Steven Lord
Steven Lord 2017 年 9 月 1 日
Multiplying a cell array by a number is not defined, regardless of what the cell in the cell array contains. So something like 3*{'a'} will error.
Multiplying a char array by a number is defined, but it will not do what you're trying to do. Since the ASCII value of 'a' is 97 (which you can find using the command double('a')) computing 3*'a' returns 291 (= 3*97).
If you have Symbolic Math Toolbox, define a to be a symbolic variable then multiply that symbolic variable by 3 to do what you're trying to do.
syms a
y = 3*a
You can check if you have Symbolic Math Toolbox installed by looking for it in the output of the ver function.

Jan
Jan 2017 年 9 月 1 日
Perhaps you do not want a symbolic calculation but a string manipulation.
c = {'a'}
b = sprintf('%d%s', 3, c{1});

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by