how to get the values of each cell in the cell array?

18 ビュー (過去 30 日間)
sheno39
sheno39 2014 年 2 月 25 日
回答済み: Jos (10584) 2014 年 2 月 26 日
here i have given my code. i have to access all the values from the cell array X{i} can anyone help me?
if true
[loc,ctr]=kmeans(hogfeat,20);
b=unique(loc);
for i=1:size(b,1)
X{i}=hogfeat(find(loc==b(i,1)));
end
Xmean = cellfun(@mean, X);
end
  2 件のコメント
Niklas Nylén
Niklas Nylén 2014 年 2 月 25 日
Please clarify what you mean by "access all the values". Do you just want to look at the values or do you want to make some calculation?
sheno39
sheno39 2014 年 2 月 25 日
i have to make some calculation.. i need to substact each element from the cell with its mean value.

サインインしてコメントする。

回答 (2 件)

Niklas Nylén
Niklas Nylén 2014 年 2 月 26 日
According to the comment "i have to make some calculation.. i need to substact each element from the cell with its mean value":
First, use non-uniform output in the first cellfun call, this will make it return a cell instead of a vector:
Xmean = cellfun(@mean, X, 'Uni', 0)
Next, use cellfun again with the @minus handle. Since this should also return a cell the uniform output parameter should be set to 0 here as well:
X2 = cellfun(@minus, X, Xmean, 'Uni', 0)

Jos (10584)
Jos (10584) 2014 年 2 月 26 日
The code below acts on a cell array C. Each element of C is an array of numbers. The anonymous function given to cellfun subtracts the mean of the array from each element of that array. It does so for each cell of C. The result is returns in a cell array D with the same size as C.
D = cellfun(@(X) X-mean(X(:)), C, 'un', 0)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by