필터 지우기
필터 지우기

I want to sum the subtraction of every element in a cell (1 column, "i" rows) with the others. Then, I want to sum all results

조회 수: 1 (최근 30일)
elementos_cons1(all(cellfun(@isempty,elementos_cons1),2), : ) = [];
B=cell(size(elementos_cons1));
C=cell(size(elementos_cons1));
D=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);
D{k}=cellfun(@sum, C{k},'UniformOutput', false);
end
C is giving me what I want: its a cell with 1 column and "i" rows, and in each row there is another cell with "i" rows that have the result for the previous loop. Now, I want to add all the results from C. Instead, D is being the same as C; I want that, for every row, there is sum result of every cell from C. What is wrong?!

답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 11일
D{k} = sum(C{k}, 2);
perhaps. This would be the row sum.
  댓글 수: 1
Eduardo Rocha
Eduardo Rocha 2016년 11월 11일
It says "Undefined function 'sum' for input arguments of type 'cell'." I used
D{k} = sum(cell2mat(C{k}), 2);
but D is being the same as C again.

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

카테고리

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