Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repeat a character multiple times as a MATLAB array?

Given a single string value in a MATLAB character array:

['12 N']

How can I repeat this value X times in a new character array?

For example:

X = 5

['12 N'; '12 N'; '12 N'; '12 N'; '12 N']
like image 815
Borealis Avatar asked Mar 07 '14 18:03

Borealis


1 Answers

Use the repmat function:

A = ['12 N'];
X = 5
Output = repmat(A, X, 1);

will result in a character array.

Depending on your end usage, you may want to consider using a cell array of strings instead:

Output = repmat({A},X,1);
like image 178
DaveH Avatar answered Sep 27 '22 23:09

DaveH