Rows mean collapse in big matrix
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 26 Juin 2016
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);
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!