MATLAB: How to assign a column of text string to another variable

MATLABtext string

For example,
A = repmat('test', 5,1);
If I want to assign A to B, why the below doesn't work? What is the right way to do it?
B([20+1:20+5,1) = A
Many thanks,

Best Answer

A = repmat('test', 5,1);
replicates the 1x4 char array 'test' 5 times along the rows, resulting in a 5x4 matrix of 20 characters
B([20+1:20+5,1) = A
attemps to store these 20 characters at indices 21 to 25 of row 1 of B. That's room for just 5 characters, so yes it's not going to work.
Note that you're working with char vectors, not string arrays. Perhaps you intended to work with string arrays. char vectors and string arrays work differently. Your code would work with string arrays. string arrays use ", not ' as the enclosing symbol:
%this would work. No idea if that's what you want
A = repmat("test", 5, 1);
B(20+(1:5), 1) = A;
However, note that you don't even need the repmat in the above. Assigning a scalar to a vector automatically replicates the scalar:
A = "test";
B(20+(1:5), 1) = A;