How to copy an array with some left-over indicies also added on?

2 ビュー (過去 30 日間)
Tyler
Tyler 2016 年 5 月 3 日
回答済み: Azzi Abdelmalek 2016 年 5 月 3 日
I have the following vector I would like to copy:
a = [1;2;3;4;5]
I would like my resulting vector to be
b = [1;2;3;4;5;1;2;3;4;5;1;2;3;4;5;1;2;3]
Where it is [a] 3 times repeated, and then repeats the next 3 indicies of [a], but not the whole vector. The repmat command will not allow me to repeat it by anything other than an integer. Is there a way to specify how many more indicies I want without having to do it manually?
Thanks!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 3 日
You can use repmat
a = [1;2;3;4;5]
b=[repmat(a,3,1); a(1:3)]

その他の回答 (2 件)

the cyclist
the cyclist 2016 年 5 月 3 日
Here's one way:
b = a(mod(0:17,numel(a))+1)

Fangjun Jiang
Fangjun Jiang 2016 年 5 月 3 日
n=3;
b=cat(1,repmat(a,n,1),a(1:n))

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by