How to put multiple elements in a cell?
18 次查看(过去 30 天)
显示 更早的评论
I am loading in a mat file that contains a 6 X 191 cell (contains pixels).
*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).
% 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 个评论
回答(1 个)
KSSV
2020-4-10
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!