# Computer Science (MATLAB)

• GreenPrint
In summary, the user is struggling with segmenting a vector's characters into a new vector with 8 columns and as many rows as needed. They have figured out how to make the input vector a multiple of 8 characters in length, but are struggling with the segmentation process. They have tried using a for loop and the reshape function, but have encountered issues with the length of the original vector and the direction of the reshape. They are looking for help on how to properly segment the vector into a 2x8 matrix.

#### GreenPrint

Given an arbitrary one dimensional vector v imputed by the user
for example v='Helllllloooooo'
or
v='Helo'
I was able to append empty characters onto anyone dimensional vector that the user can enter so that way the total length of the vector is a multiple of 8 characters of long or not add any empty characters onto the vector if it's length is already an exact multiple of 8

I'm struggling with segmenting this vector's characters to a vector that has as many rows as needed that each have exactly 8 column's

for example
function('Hello World!')
and the function returns
g=Hello Wo
rld!
were it adds blank characters so that there is actually blank spaces after the exclamation mark to make the second row 8 characters in length.

I'm all set on making the input to the function be a multiple of 8 characters in length regardless of what string the user inputs. I'm struggling with segmenting this new message like in the example above because the message can be any multiple of 8... I tried using a four loop and just taking off multiples of 8 and setting them to a new row of another vector but am struggling because of the fact that the message can be any length

basically how do I turn any string who's length is a multiple of 8 (i figured out how to append blank spaces so that it would always be a multiple of 8) and segment it into something like this
function('Hello World!')
and the function returns
g=Hello Wo
rld!

I hope that makes sense
thanks for any help
if it's not clear what I'm trying to do please let me know.

I tried taking any string such as
V='helloooooooooo '
and using
reshape(V,2,8)
but it returns something like this

hlooooo
elooo

which is not what i wanted...

So you want g to be a 2x8 matrix in the case you listed?
The reshape you used there won't work as reshape goes down columns, not across rows. To fix this though, use reshape(V,8,2)' which gives you the transpose of the reshape vector.
Don't forget to pad out the vector so it's the right size beforehand though!