문제

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']
도움이 되었습니까?

해결책

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);

다른 팁

repmat is the obvious way to go, but just for the heck of it you could use kron:

A = ['12 N'];
X = 5
B = char(kron(A,ones(X,1)))

Silly, yes...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top