MATLAB: Matrix with some sort of pattern

matrix manipulationonespatterns in matricesrepmat

Hi everybody, i would like to make a matrices like this [1,1,1,1,1,0,0,0,0,0;0,0,0,0,0,1,1,1,1,1;] or this [-1 0 0;-1 0 0;-1 0 0;-1 -1 0;-1 -1 0; -1 -1 0;-1 -1 -1;-1 -1 -1;-1 -1 -1] in such a way that 'for' loop would be unnecessary.i was thinking something about repmat or so,because of the pattern that this kind of matrices seem to have.any ideas??? Thank you!!

Best Answer

You could use KRON
>> kron(eye(2), ones(1,5))
>> kron(tril(ones(3)),-ones(3,1))