Average of specific columns from cells in cell array
Mostrar comentarios más antiguos
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!
Respuestas (2)
James Tursa
el 5 de Oct. de 2017
Editada: James Tursa
el 5 de Oct. de 2017
result = cellfun(@(x)mean(x(:,1)),alldata(4:84));
9 comentarios
AIDA AMROUSSIA
el 5 de Oct. de 2017
AIDA AMROUSSIA
el 5 de Oct. de 2017
James Tursa
el 5 de Oct. de 2017
Editada: James Tursa
el 5 de Oct. de 2017
You said (I think) that alldata had at least 84 elements. What does this show:
size(alldata)
AIDA AMROUSSIA
el 6 de Oct. de 2017
AIDA AMROUSSIA
el 6 de Oct. de 2017
Andrei Bobrov
el 6 de Oct. de 2017
Please attach here your alldata.
James Tursa
el 6 de Oct. de 2017
Are some of the cell elements empty?
AIDA AMROUSSIA
el 7 de Oct. de 2017
James Tursa
el 7 de Oct. de 2017
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
el 7 de Oct. de 2017
0 votos
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!