In the following sparse matrix:
A=[1 1 1 3];
C = sparse(A',1:length(A),ones(length(A),1),4,4);
C =
(1,1) 1
(1,2) 1
(1,3) 1
(3,4) 1
>>full(C)
ans =
1 1 1 0
0 0 0 0
0 0 0 1
0 0 0 0
How could I compute the mean value of non-zero elements in each row? I couldn't use the built-in mean function of matlab on these sparse matrices. I found this similar question and I can apply it to my problem
[row, ~, v] = find(C);
K>> rowmean = accumarray(row, v, [], @mean);
K>> rowmean
rowmean =
1
0
1
However, I would like to get zero value for the last row instead of this row being removed from the answer.