Rows mean collapse in big matrix
이전 댓글 표시
Hi,
I have a big matrix (40448x47). I would like to collapse some rows with it mean. For example, if i have:
avarageNumb = 3
ma =
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
79 6 13 95 97 29 31 38 45 72
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59
I would like 3 to have a matrix 4x10 with rows mean (first row is the mean of the first three, second row is the mean of the 4-5-6 rows, third row is the mean of 7-8-9 rows, and fourth row is the 10 row).
I'm trying to design an algo with nested loop, however i think that Matlab can help me with some function that i do not know (I am a newbie in Matlab)! :)
Thanks, Marco
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2016년 6월 26일
avarageNumb = 3;
ma =[...
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
79 6 13 95 97 29 31 38 45 72
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59];
ii = ceil((1:size(ma,1))'/avarageNumb);
[jj,kk] = ndgrid(ii,1:size(ma,2));
out = accumarray([jj(:),kk(:)],ma(:),[],@mean);
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!