MATLAB: How can i write this statement labels=[1;​1;1;1;1;1;​1;1;1;1;1;​1;1;1;1;1;​1;1;1;1;1;​1;1;1;2;2;​2;2;2;2;2;​2;2;2;2;2;​2;2;2;2;2;​2;2;2;2;2;​2;2;3;3;3;​3;3;3;3;3;​3;3;3;3;3;​3;3;3;3;3;​3;3;3;3;3;​3;]; in compress form

arraysmatrices

how to write it in compact form avoiding repetition

Best Answer

labels = kron((1:3)',ones(24,1));
or
labels = reshape(ones(24,1)*(1:3),[],1);