3D image stack; determine mean of individual arrays; error code
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,I have a 1000x1000x1952 uint8 3D image array (Array), and would like to get the mean value of each individual array "image" and subsequently put these in a 1952x1 array (meanArray).
The code I use is:
meanArray= mean(Array,[1 2])
the error code I get is: Error using sum "Dimension argument must be a positive integer scalar within indexing range. Error in mean (line 87) y = sum(x,dim,flag);"
What am I missing here? Thanks! Barry
0 commentaires
Réponse acceptée
Matt J
le 5 Oct 2018
Modifié(e) : Matt J
le 5 Oct 2018
For some reason, mean was not written to let you operate along multiple dimensions in the same call. One alternative is to use sepblockfun (Download).
[m,n,p]=size(Array);
meanArray = sepblockfun(Array, [m,n,1], 'mean');
2 commentaires
Matt J
le 9 Oct 2018
@Janssen, if you look inside sepblockfun, you will see that it is equivalent to Stephen's proposal, but more general, in that it allows you take means/maxes over different block sizes. There is some overhead from this additional flexibility, which is why you might see slightly slower performance.
Plus de réponses (2)
Stephen23
le 5 Oct 2018
squeeze(mean(mean(Array,1),2))
2 commentaires
Stephen23
le 9 Oct 2018
Modifié(e) : Stephen23
le 9 Oct 2018
@B Janssen: so you actually used my faster answer, but accepted Matt J's answer that you did not use? Confusing.
Note that you can also vote for answers, which is any easy way to show thanks to the volunteers who helped you. It is nice to get a vote as a small sign of appreciation.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!