Average of specific columns from cells in cell array

Hi,
I am new to cell array function so excuse me if the answer is obvious.I have a cell array data 1x84 each and each cell is has five columns by variable rows number. I am trying to average the first column of cells 4 to 84. how do I do that? I wasn't successful using
A=cellfun(@mean,alldata{1,5:84}(:,1))
Thank you!

답변 (2개)

James Tursa
James Tursa 2017년 10월 5일
편집: James Tursa 2017년 10월 5일
result = cellfun(@(x)mean(x(:,1)),alldata(4:84));

댓글 수: 9

When using your suggestion I get this error message Index exceeds matrix dimensions.
Error in Nano>@(x)mean(x(:,1))
Error in Nano (line 31) result = cellfun(@(x)mean(x(:,1)),alldata(4:84));
Thank you for your suggestion though!
You said (I think) that alldata had at least 84 elements. What does this show:
size(alldata)
in the variable windows is 1x84 cell
Please attach here your alldata.
Are some of the cell elements empty?
yes some cells are empty. below is the alldata file
Assuming that a 0 result for those empty cells is OK, then try this:
alldata484 = alldata(4:84);
e = ~cellfun(@isempty,alldata484);
result = zeros(size(alldata484));
result(e) = cellfun(@(x)mean(x(:,1)),alldata484(e));

댓글을 달려면 로그인하십시오.

AIDA AMROUSSIA
AIDA AMROUSSIA 2017년 10월 7일

0 개 추천

Attached is the alldata file. Yes it contains some empty sheets.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2017년 10월 5일

댓글:

2017년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by