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 CenterFile Exchange에서 Parallel Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by