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?

 채택된 답변

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

추가 답변 (2개)

n = 3;
r = 24;
labels = reshape(repmat((1:n),r,1),[],1);

댓글 수: 4

can you please make me understand this code?
Why don't you just try it out? That is probably the best way to understand it. Do 1:n first. Then do repmat((1:n),r,1). Then do the 'reshape' of it.
Thanks.. Roger Stafford for that new information.

댓글을 달려면 로그인하십시오.

Matt J
Matt J 2014년 6월 25일
편집: Matt J 2014년 6월 25일
Using KronProd ( link )
>> 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

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

질문:

2014년 6월 25일

댓글:

2014년 6월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by