How to put multiple elements in a cell?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am loading in a mat file that contains a 6 X 191 cell (contains pixels).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283247/image.png)
*I am not able to upload a zip file of the mat file because of the size so I took a screenshot.
I want to calculate the mean, medican, std, skewness, and kurtosis for each column.
Then I want to take each of the column's statistic and put it in a array with 5x1 elements in each cell. (1 x 191 cell array with 5 elements in each cell)
Is that possible? In the future, I want to make a for loop out of this, so I can go through multiple mat files.
I have this code so far.
I tried using the vertcat and I ended up getting a 5 X 191 double (i don't know if it turned to a matrix).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283248/image.png)
% lead feats.mat
load('Feats.mat');
% calculate various statistics per column
feat_mean = arrayfun(@(k) mean([featints{1,k} ; featints{2,k}]), 1:size(featints,2));
feat_med = arrayfun(@(k) median([featints{1,k} ; featints{2,k}]), 1:size(featints,2));
feat_std = arrayfun(@(k) std([featints{1,k} ; featints{2,k}]), 1:size(featints,2));
feat_skw = arrayfun(@(k) skewness([featints{1,k} ; featints{2,k}]), 1:size(featints,2));
feat_kurt = arrayfun(@(k) kurtosis([featints{1,k} ; featints{2,k}]), 1:size(featints,2));
% combine all the stats into different rows
combine_feat_stat = vertcat(feat_mean, feat_med, feat_std, feat_skw, feat_kurt);
% 5X1 elements in each cell
0 commentaires
Réponses (1)
KSSV
le 10 Avr 2020
Let A be your 6*191 cell array.
[m,n] = size(A) ;
M = zeros(1,n) ; % initialize mean
for i = 1:n
C = cell2mat(A(:,i)) ; % convers the first column of cells into array
M(i) = mean(C) ;
end
1 commentaire
Nandini Chatterjee
le 10 Avr 2020
Modifié(e) : Nandini Chatterjee
le 10 Avr 2020
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!