1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Computer Science (MATLAB)

  1. Nov 14, 2011 #1
    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 any one 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...
     
  2. jcsd
  3. Nov 14, 2011 #2
    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!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Computer Science (MATLAB)
Loading...