Create a list of list and take the mean

조회 수: 2 (최근 30일)
Tung
Tung 2024년 2월 18일
편집: Alexander 2024년 2월 18일
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
Voss
Voss 2024년 2월 18일
mean(vertcat(aps{:}),1)
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