How to concatenate a (REAL) string vector?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Csaba
el 22 de Abr. de 2021
I have a string matrix i.e.
A=["abcd",.....,"efghijk";...
. ...
. ...
. ...
"lm",......, "opkq"];
How to concatenate easily the rows of this matrix to get the result:
"abcdefghijk"
.
.
.
"lmopkq"
as a column vector?
0 comentarios
Respuesta aceptada
Stephan
el 22 de Abr. de 2021
Editada: Stephan
el 22 de Abr. de 2021
A=["abcd","efghijk"; "lm", "opkq"]
B = A(:,1) + A(:,2)
The more general solution (independent from number of rows or columns of your input is:
A=["abcd","efghijk", "1111"; "lm", "opkq", "2222"; "fdds<jgf", "dfkjf", "ldfkj"; "<ksajfjf", "fjjf", "fkkgfkdsw43"]
B = join(A,'',2)
5 comentarios
Stephen23
el 22 de Abr. de 2021
Editada: Stephen23
el 22 de Abr. de 2021
ERASE is superfluous**, simply specify both the delimiter and dimension:
A=["abcd","efghijk", "1111"; "lm", "opkq", "2222"; "fdds<jgf", "dfkjf", "ldfkj"; "<ksajfjf", "fjjf", "fkkgfkdsw43"];
B = join(A,'',2)
** and incorrect: consider what would happen if the strings themselves contain spaces.
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!