sum the elements in the cell array

조회 수: 4 (최근 30일)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2015년 11월 6일
댓글: the cyclist 2015년 11월 6일
a = { 1 2 3; 4 5 6; 7 8 9}
How to use the cellfun to sum the element row wise?

채택된 답변

the cyclist
the cyclist 2015년 11월 6일
Is there a specific reason you are using a cell array? This is easy with a numeric array:
a = [ 1 2 3; 4 5 6; 7 8 9 ];
sum(a,1) % Sum down columns
sum(a,2) % Sum across rows
  댓글 수: 2
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2015년 11월 6일
elements are in the cell ....... i dont want to convert cell2mat..... it works only for matrix
the cyclist
the cyclist 2015년 11월 6일
Well you have to tell MATLAB somehow that the content of the cell are a numeric variable that can be summed, otherwise it could try to sum the cell array
a = {'red','donald trump',-Inf}
If the data are already in a cell array, then I don't think there is a better way than cell2mat to do this conversion.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by