フィルターのクリア

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 6 月 25 日
labels = kron((1:3)',ones(24,1));
or
labels = reshape(ones(24,1)*(1:3),[],1);
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2014 年 6 月 25 日
編集済み: Andrei Bobrov 2014 年 6 月 25 日
please read about ones, kron, reshape and repmat.

サインインしてコメントする。

その他の回答 (2 件)

Roger Stafford
Roger Stafford 2014 年 6 月 25 日
n = 3;
r = 24;
labels = reshape(repmat((1:n),r,1),[],1);
  4 件のコメント
PREMANAND
PREMANAND 2014 年 6 月 25 日
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

Community Treasure Hunt

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

Start Hunting!

Translated by