How to assign a column of text string to another variable?
Show older comments
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,
6 Comments
Adam Danz
on 9 Mar 2020
What is B? A char array? A string array? A cell array?
Adam Danz
on 9 Mar 2020
You can use class(var) to determine the class of a variable var.
Yes, it's problematic. Your definition of B creates a double precision numeric vector. But A is a char array.
Perhaps you're looking for
% Cell array of chars
A = repmat({'test'}, 5,1);
B = cell(100000,1);
B([20+1:20+5]) = A;
or
% String array
A = repmat("test", 5,1);
B = repmat("", 100000,1)
B([20+1:20+5]) = A;
Leon
on 9 Mar 2020
Leon
on 9 Mar 2020
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!