Mean of cell array containing matrices

1 回表示 (過去 30 日間)
alicia che
alicia che 2020 年 4 月 15 日
コメント済み: alicia che 2020 年 4 月 17 日
Hi,
I have a 1x10 cell array, each contains a matrix of nx2 (8x2, 9x2, 6x2, 7x2, 7x2...). I would like to take the mean of each column of the matrices, and re-sort the cell array accoring to the means. I tried to use mean and cee2mat and ran into dimension problems...Thank you in advance for helping!!!

採用された回答

Peng Li
Peng Li 2020 年 4 月 15 日
Not sure what do you mean by "re-sort the cell array according to the means" as you have two means corresponding to each cell. Below example shows how to take the means and each column within a cell, and sort the cell based on the mean of the first column.
% generated a 1 by 10 cell, each with a n*2 random matrix.
% n generated randomly within 1 and 20
ind = 1:10;
testCell = arrayfun(@(x) rand(randi(20), 2), ind, 'UniformOutput', 0);
% mean of each column within cell
meanInCell = cell2mat(cellfun(@mean, testCell, 'UniformOutput', 0)');
% sort by the mean of first column
[~, indSort] = sort(meanInCell(:, 1));
sortTestCell = testCell(indSort);
  1 件のコメント
alicia che
alicia che 2020 年 4 月 17 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by