필터 지우기
필터 지우기

How to reshape an array horizontally

조회 수: 27 (최근 30일)
Brett Baxter
Brett Baxter 2020년 9월 22일
답변: Jérôme 2024년 4월 22일
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
Brett Baxter
Brett Baxter 2020년 9월 22일
Understood, thank you
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