Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Creating m by m matrix in matlab

  1. May 3, 2012 #1
    hi all,

    i have a vector, z which size is 1 by m.
    z = [1 2 3 4 5 6 7 8]

    then i want to make a matrix with m by m
    Z= [z; z; z; z; z; z; z; z]

    if m become bigger i couldn't do it like mentioned above. how could i generate the matrix by a single command?

    thank you in advance.
  2. jcsd
  3. May 5, 2012 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    A kind of brute fortish method would be
    for r=1:m

    I don't know if there's a vectorized way to do it but there probably is
  4. May 7, 2012 #3
    See the repmat() function. For your purpose its repmat(z, size(z)(2), 1)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook