mean of cells in loop with different dimensions
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nooshin Mahmoodi
le 20 Oct 2018
Commenté : Image Analyst
le 20 Oct 2018
I have a loop, and creat B{i,1} on it. now I need to calculate the mean of each cell.i used meanOfCities(i)= mean(cell2mat(B(i,1))) ; it workes just for 4 loop, and then this error : Index exceeds matrix dimensions. will occure.
0 commentaires
Réponse acceptée
Image Analyst
le 20 Oct 2018
Inside the loop, right after you assigned B{i, 1} take the mean and assign that to a vector:
cellContents = B{i, 1}; % A vector, matrix, or higher dimensional array - whatever it is...
theMeans(i) = mean(cellContents(:));
Now, after your loop, theMeans will be the mean of every cell that you've assigned.
2 commentaires
Image Analyst
le 20 Oct 2018
Without the loop, it really depends on what is in the cells. If all the cells contain the same size matrix you might be able to just use cell2mat() and then use mean().
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!