Averaging and Storing Stacked Cell Array With 'NaN' Values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dilchand Nauth
le 21 Juin 2019
Commenté : Dilchand Nauth
le 21 Juin 2019
I have a stacked cell array called 'nitrogenCell' (Image 1 below). When I click on each of the 450x450 double, I get 'nitrogenCell{1,1}' (Image 2 below), 'nitrogenCell{2,1}' (Image 3 below), and 'nitrogenCell{3,1}' (Image 4 below), respectively. I want to average each position of each different matrix and store the resulting average value in a new matrix. For example, the first position in 'nitrogenCell{1,1}' is (1,1) and it's value is 1.4730e-04, the first position of 'nitrogenCell{2,1}' is (1,1) and it's value is -7.7473e-05, and the first position of 'nitrogenCell{3,1}' is (1,1) and it's value is 1.3875e-04. I want to average these values and store them in position (1,1) of a new matrix called 'nitrogenCellAveraged'. Then I want to continue to do this for every position of each matrix within the cell array. So next, I would average the values of positions (1,2) of each 'nitrogenCell' matrix and store it in position (1,2) of the same new matrix called 'nitrogenCellAveraged', and so on. Note also that these matrices contain 'NaN' values in certain positions and I want to ignore these 'NaN' values in the averaging process. I know a 'for loop' is ideal, but I am not sure how to do this. I am new to MATLAB. Thank you for your help!
(Image 1)
(Image 2)
(Image 3)
(Image 4)
0 commentaires
Réponse acceptée
Matt J
le 21 Juin 2019
Modifié(e) : Matt J
le 21 Juin 2019
Averages = mean( cat(3,nitrogenCell{:}) ,3,'omitnan');
3 commentaires
Matt J
le 21 Juin 2019
Modifié(e) : Matt J
le 21 Juin 2019
Then your cell contents aren't 450x450 like you told us. It works totally fine for me,
nitrogenCell=num2cell(rand(450,450,3),[1,2]);
nitrogenCell=nitrogenCell(:);
Averages = mean( cat(3,nitrogenCell{:}) ,3,'omitnan');
>> whos nitrogenCell Averages
Name Size Bytes Class Attributes
Averages 450x450 1620000 double
nitrogenCell 3x1 4860336 cell
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!