How to concatenate a (REAL) string vector?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephan
2021-4-22
编辑:Stephan
2021-4-22
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 个评论
Stephen23
2021-4-22
编辑:Stephen23
2021-4-22
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!