Create a list of list and take the mean

2 次查看(过去 30 天)
Hi everyone
I am new to Matlab (I came from a Python background).
I have a question about creating a list of arrays and calculating their componentwise means. I know how to this in python using numpy array. I tried to apply the same logic in Matlab but somehow it does not work.
Please find below one example. I want to calculate the componentwise mean of aps. Perhaps, I used the wrong data structure for the aps?
Thank you very much.
aps = {};
for i = 1:length(locs)
aps{i} = [i i+1 i+2];
end

采纳的回答

Walter Roberson
Walter Roberson 2024-2-18
cellfun(@mean, aps) 
  4 个评论
Tung
Tung 2024-2-18
That makes sense. My understanding is that the function cell2mat and vertcat transform the aps into a 2D-array. Once it is done, we can calculate the mean on one of the axes. This is similar to Python. Thank you both!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by