# How to create image from arrays by random themself ?

조회 수: 1 (최근 30일)
Jenifer NG 2022년 7월 14일
댓글: Jenifer NG 2022년 7월 14일
Dear all,
I want to create a image by using defined arrays a b c in a ramdom step to get a image 44x400 pixel
Could anyone help me?
a = [119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 38 42 36 30 35 17 23 29 29 31 27 18 17 51]
b = [144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 36 31 33 37 23 27 24 32 23 27 28 23 5 32]
c = [133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 17 17 30 16 10 21 26 30 29 21 18 11 19 48]
newimage = [ a
b
c
b
c
c
b
a
....
400]

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

### 채택된 답변

Jonas 2022년 7월 14일
편집: Jonas 2022년 7월 14일
a = [119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 38 42 36 30 35 17 23 29 29 31 27 18 17 51];
b = [144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 36 31 33 37 23 27 24 32 23 27 28 23 5 32];
c = [133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 17 17 30 16 10 21 26 30 29 21 18 11 19 48];
together=[a;b;c];
numOfRows=400;
randomRowsIdx=randi(3,numOfRows,1);
together(randomRowsIdx,:)
ans = 400×44
133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35
note that the result is 400x44 and not 44x400.
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Jonas 2022년 7월 14일
just run
randomRowsIdx=randi(3,numOfRows,1);
together(randomRowsIdx,:)
inside your loop and write the rest of the code before it:
a = [119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 38 42 36 30 35 17 23 29 29 31 27 18 17 51];
b = [144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 36 31 33 37 23 27 24 32 23 27 28 23 5 32];
c = [133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 17 17 30 16 10 21 26 30 29 21 18 11 19 48];
together=[a;b;c];
numOfRows=400;
for x=1:3
randomRowsIdx=randi(3,numOfRows,1);
myCurrentImage=together(randomRowsIdx,:)
end
myCurrentImage = 400×44
119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35
myCurrentImage = 400×44
119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42
myCurrentImage = 400×44
144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 119 79 76 101 119 99 72 77 94 82 76 84 92 86 63 54 45 47 59 69 56 59 52 48 48 41 41 38 41 42 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 133 112 97 92 79 75 78 74 60 74 72 68 76 70 60 54 56 46 43 54 46 40 43 41 41 36 41 39 34 30 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35 144 118 123 109 88 78 77 71 78 80 74 82 87 78 71 59 39 53 35 37 41 40 26 37 40 38 31 36 40 35
Jenifer NG 2022년 7월 14일
Thanks you

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

### 카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by