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?
조회 수: 2 (최근 30일)
이전 댓글 표시
how to write it in compact form avoiding repetition
댓글 수: 0
채택된 답변
Andrei Bobrov
2014년 6월 25일
labels = kron((1:3)',ones(24,1));
or
labels = reshape(ones(24,1)*(1:3),[],1);
추가 답변 (2개)
Matt J
2014년 6월 25일
편집: Matt J
2014년 6월 25일
>> labelsKP=KronProd({ones(2400,1), (1:3).'});
you can get even more compression. For comparison,
>> labels = kron((1:3)',ones(2400,1));
>> whos labels labelsKP
Name Size Bytes Class Attributes
labels 7200x1 57600 double
labelsKP 7200x1 19660 KronProd
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!