Matlab - building a matrix by merging the same raw vector multiple times

前端 未结 2 1546
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 07:04

Is there a matlab function which allows me to do the following operation?

x = [1 2 2 3];

and then based on x I want to build the ma

2条回答
  •  北海茫月
    2020-12-06 07:39

    You could try using vertcat, like this:

    x = [1 2 2 3];
    m = vertcat(x,x,x,x);
    

    Or even simply:

    x = [1 2 2 3];
    m = [x;x;x;x];
    

    EDIT:

    for multiples of x, you can do:

    x = [1 2 2 3];
    m = [x;2*x;3*x];  %  [1 2 2 3; 2 4 4 6; 3 6 6 9]
    

    EDIT2:

    For an arbitrary number of x's in m...

    n = 3; % number of repetitions...
    x = [1 2 2 3];
    m = [];
    for i=1:n
        m = [m;x];
    end
    

提交回复
热议问题