How to reshape an array horizontally

25 visualizaciones (últimos 30 días)
Brett Baxter
Brett Baxter el 22 de Sept. de 2020
Respondida: Jérôme el 22 de Abr. de 2024 a las 11:34
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?

Respuesta aceptada

Star Strider
Star Strider el 22 de Sept. de 2020
Using the reshape function:
text1 = ['words'; 'words'; 'words']
text2 = reshape(text1', 1, [])
producing:
text1 =
3×5 char array
'words'
'words'
'words'
text2 =
'wordswordswords'
.
  6 comentarios
Brett Baxter
Brett Baxter el 22 de Sept. de 2020
Understood, thank you
Star Strider
Star Strider el 22 de Sept. de 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Iniciar sesión para comentar.

Más respuestas (1)

Jérôme
Jérôme el 22 de Abr. de 2024 a las 11:34
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"

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by