I need help finding the average across a 1x5 cell array

6 ビュー (過去 30 日間)
Abigail Flores
Abigail Flores 2018 年 5 月 12 日
編集済み: Jan 2018 年 5 月 12 日
I have a 1x5 cell array, each with a 4x5 matrix. I need to average the data (in the first row, and all columns of each matrix) across all 5 cells. Any suggestions on how to approach this?

回答 (1 件)

Jan
Jan 2018 年 5 月 12 日
編集済み: Jan 2018 年 5 月 12 日
% Create some test data:
C = cell(1, 5);
for k = 1:5
C{k} = rand(4, 5);
end
M = cat(3, C{:}); % convert cell to 3-dim numerical array
s = size(M);
Mavg1 = reshape(mean(M, 1), s(2:3))
Mavg2 = reshape(mean(M, 2), s([1, 3]))
For mathematical operations a multi-dimensional numerical array is useful, while a cell array is not.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by