How to reshape an array horizontally

17 次查看(过去 30 天)
I wanted to know how to go about reshaping a character array horizontally, starting from the first index in the first row, and then the second and so on. So I want to change:
text =
3×5 char array
'words'
'words'
'words'
Into
text =
1x15 char array
'wordswordswords'
How do I do this?

采纳的回答

Star Strider
Star Strider 2020-9-22
Using the reshape function:
text1 = ['words'; 'words'; 'words']
text2 = reshape(text1', 1, [])
producing:
text1 =
3×5 char array
'words'
'words'
'words'
text2 =
'wordswordswords'
.
  6 个评论
Star Strider
Star Strider 2020-9-22
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

请先登录,再进行评论。

更多回答(1 个)

Jérôme
Jérôme 2024-4-22
I know it's not the class used in que question, but it's just to share how to do it with strings.
In case a string array is used instead of a char array, this can be done with the function strjoin:
text_1 = ["words" ; "words" ; "words"]
text_1 = 3x1 string array
"words" "words" "words"
text_2 = strjoin(text_1, "")
text_2 = "wordswordswords"

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by