user2983722
user2983722

Reputation: 215

MATLAB: constructing a column vector whose only element is character A

I want a column vector that contains only the character A, that is,

 A
 A
 A
 A

like this. So i have tried

 'A'*ones(4,1)

But in place of A, it takes on value 65. How can i get A ?

Upvotes: 2

Views: 41

Answers (2)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

Multiplication of chars with doubles gives doubles; the charis cast to double, using the corresponding ASCII value.

Just cast back to char:

char('A'*ones(4,1))

but probably Luis' answer is faster ;)

Upvotes: 3

Luis Mendo
Luis Mendo

Reputation: 112749

You can do it this way:

repmat('A',4,1)

Or use your approach but include char to convert back to string after the multiplication:

char('A'*ones(4,1))

Upvotes: 4

Related Questions