Mean of a cell array with different cell sizes?
조회 수: 1 (최근 30일)
이전 댓글 표시
Mean of a cell array with different cell sizes?
% This works:
a = {[1 3 4 5];[7 7 8 2];[5 4 1 9]}
mean(cell2mat(a),2)
% but this does not work:
a = {[1 3 4 5];[7 7 8 2];[5 4 1]}
mean(cell2mat(a),2)
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 11월 28일
If the data in the cell array is compatible for concatenation, concatenate them and use mean for the specific dimension -
a = {[1 3 4 5];[7 7 8 2];[5 4 1 9]}
b = cat(1,a{:})
m = mean(b, 2)
If the data in the cell array is not compatible for concatenation, the best approach would be to pre-allocate the output and use a for loop. You could use cellfun() but that is just a for loop in disguise.
댓글 수: 6
Dyuman Joshi
2023년 11월 28일
@Sim, Using the name-argument pair will give the output as a cell array.
a = {[1 3 4 5];[7 7 8 2];[5 4 1]}
cellfun(@mean,a)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!