Cell to matrix average

2 ビュー (過去 30 日間)
Articat
Articat 2019 年 9 月 17 日
回答済み: the cyclist 2019 年 9 月 17 日
I have a cell array consising of 93x1 cells(named velocitydata). Each cell consists of a 145x147x19 matrix. I want to average the cell array so the result will be an averaged 145x147x19 matrix.
I tried this:
A = cellfun(@mean, velocitydata)
I keep getting the "Did you mean: A = cellfun(@mean, xVelocityData, 'UniformOutput', true, 'UniformOutput', false) "
I tried that but it returns me the exact same thing. Can someone point me in the right direction?
Anything would help. Thanks!

回答 (2 件)

Rik
Rik 2019 年 9 月 17 日
Something like this should work for you:
%generate some example data
data=cell(93,1);
for n=1:93
data{n}=rand(45,147,19);
end
number_of_dims=ndims(data{1});
new_data=cat(number_of_dims+1,data{:});
avg=mean(new_data,number_of_dims+1);

the cyclist
the cyclist 2019 年 9 月 17 日
I believe this does what you want:
B = squeeze(mean(reshape(cell2mat(A),93,145,147,19)));

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by