Create matrix with periodic increments

20 ビュー (過去 30 日間)
T D
T D 2016 年 4 月 14 日
編集済み: T D 2016 年 4 月 14 日
I want to create a matrix according to this logic:
Let's say I have a base vector like [1 2 3 4 5 6]'. First I want to replicate it 4 times each time increasing by 10. So after this step I will have
[1 2 3 4 5 6 11 12 13 14 15 16 21 22 23 24 25 26 31 32 33 34 35 36 41 42 43 44 45 46]'
and then I want to take this column and replicate it 20 times (my bad I meant 19 new copies), each time increasing by 1. So the next column would be
[2 3 4 5 6 7 12 13 14 15 16 17 22 23 24 25 26 27 32 33 34 35 36 37 42 43 44 45 46 47]'
and so on
I can't find a way to do this. I want the implementation to be vectorized, I don't want to use for loops.

採用された回答

Stephen23
Stephen23 2016 年 4 月 14 日
編集済み: Stephen23 2016 年 4 月 14 日
The function bsxfun is really handy for these kind of tasks:
>> X = [1;2;3;4;5;6];
>> Y = bsxfun(@plus,X,0:10:40);
>> Z = bsxfun(@plus,Y(:),0:20);
>> Z
Z =
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  1 件のコメント
T D
T D 2016 年 4 月 14 日
last part should be 0:19, I was a little inaccurate in the question I guess.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by