![](/img/trans.png)
[英]Matlab how to 'sort' the elements of an entire cell array and access the largest values
[英]How to access and standardize cell array elements (Matlab)
我有一个元胞数组数据结构,我想标准化它的元素。 如何将zscore
或均值和标准差应用于每个单元格数组? 我尝试执行以下操作,但不正确。 下面的代码随机生成 50 组不同的数据,每组 1000 个元素。 我什至尝试了以下cellfun(@(x)(x-mu)./sg,X,'UniformOutput',false)
但我无法计算单元结构的mu
(平均值)和sg
(标准偏差)。 请帮忙。
for n = 1: 50
x=rand(1,1000);
X(n)= {x} ;
end
XV = zscore(X);
zscore
是统计工具箱中的一个函数,我没有。 该文档说您可以使用'all'
选项将其应用于标准化矩阵(注意!这是 MATLAB R2018b 的新功能):
zscore(X,0,'all'); % won't work in versions of MATLAB before R2018b
如果像我一样,你没有这个工具箱,它应该相当于:
(X - mean(X(:))) / std(X(:));
所以我们可以像这样写一个匿名函数:
standardize = @(X)(X - mean(X(:))) / std(X(:));
或等效地
standardize = @(X)zscore(X,0,'all');
现在,您可以使用cellfun
将此函数应用于数组中的所有矩阵:
X = cell(5,3);
for ii=1:numel(X)
X{ii} = rand(1,1000);
end
XV = cellfun(standardize,X,'UniformOutput',false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.