필터 지우기
필터 지우기

I have a cell C that has "i" rows. Inside each row, there is another cell with "i" rows, but each row contains a number now. How can I make the total sum of all numbers that are in all cells of C?

조회 수: 3 (최근 30일)
elementos_cons1(all(cellfun(@isempty,elementos_cons1),2), : ) = [];
B=cell(size(elementos_cons1));
C=cell(size(elementos_cons1));
for k=1:i
A=elementos_cons1{k};
for j=1:i
B{j}=A-elementos_cons1{j};
end
C{k}=cellfun(@sum, B,'UniformOutput', false);
end
After this, I have C with "i" rows and each row is another cell with "i" rows that contain the result of the operation inside the loop. I want to have the total sum (all cells inside C). I tried like this but it didn't work, D was the same as C:
D{k}=cellfun(@sum, C{k},'UniformOutput', false);
Can someone please help me? This line was supposed to have the sum of each cell in each corresponding row, and after I could use "sum" for D. However, does not work...

채택된 답변

dpb
dpb 2016년 11월 14일
sum(cell2mat([C{:}]))

추가 답변 (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