Asked by Muhendisleksi
on 1 Sep 2017

a =

'x'

>> a*3

Undefined operator '*' for input arguments of type 'cell'.

The result I want to achieve: 3*x

Answer by the cyclist
on 1 Sep 2017

Edited by the cyclist
on 1 Sep 2017

If you have a character array and you want to replicate it, use repmat:

repmat('a',1,3)

Answer by the cyclist
on 1 Sep 2017

Sign in to comment.

Answer by Steven Lord
on 1 Sep 2017

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.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## the cyclist (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/354869-how-do-you-multiply-the-letter-a-by-3#comment_481307

## Muhendisleksi (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/354869-how-do-you-multiply-the-letter-a-by-3#comment_481308

## Jan (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/354869-how-do-you-multiply-the-letter-a-by-3#comment_481324

## the cyclist (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/354869-how-do-you-multiply-the-letter-a-by-3#comment_481353

## Stephen Cobeldick (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/354869-how-do-you-multiply-the-letter-a-by-3#comment_481356

Sign in to comment.