MATLAB Answers

How to reshape an array horizontally

13 views (last 30 days)
Brett Baxter
Brett Baxter on 22 Sep 2020 at 1:03
Commented: Star Strider on 22 Sep 2020 at 2:00
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?

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 22 Sep 2020 at 1:39
Using the reshape function:
text1 = ['words'; 'words'; 'words']
text2 = reshape(text1', 1, [])
producing:
text1 =
3×5 char array
'words'
'words'
'words'
text2 =
'wordswordswords'
.

  6 Comments

Show 3 older comments
Star Strider
Star Strider on 22 Sep 2020 at 1:55
Brett Baxter — My pleasure!
so then if I want to do operations down rows instead of columns, I have to transpose first
That depends on what you want to do. Here, yes.
Brett Baxter
Brett Baxter on 22 Sep 2020 at 1:58
Understood, thank you
Star Strider
Star Strider on 22 Sep 2020 at 2:00
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (1)

Vasishta Bhargava
Vasishta Bhargava on 22 Sep 2020 at 1:47
%if true
% code
% end
k = append(text(1,1:end),text(2,1:end),text(3,1:end))

  0 Comments

Sign in to comment.

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by