How to assign a column of text string to another variable?
Ältere Kommentare anzeigen
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 Kommentare
Adam Danz
am 9 Mär. 2020
What is B? A char array? A string array? A cell array?
Adam Danz
am 9 Mär. 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
am 9 Mär. 2020
Leon
am 9 Mär. 2020
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!