MATLAB: How to reshape and repeat at the same time.

MATLAB: How to reshape and repeat at the same time.

how to reshape and repeat at the same time.

Hi guys, I have the following data
data= [1 3 7 9 2 5]
and I want the data to be as a matrix (2*6)
newdata=1 1 7 7 2 2
3 3 9 9 5 5
Please help me, and thanks in advance.

Best Answer

  • num_rows = 2;
    num_copies = 2;
    new_data = kron(reshape(data, num_rows, []), ones(1, num_copies));
    Or less verbosely,
    new_data = kron(reshape(data,2,[]),ones(1,2));
  • Add a Comment

    Your email address will not be published. Required fields are marked *