MATLAB: Kurtosis ignoring 0s in matrix

kurtosis

Hi there, I was wondering I have a matrix A of size 295×34. I want to do the kurtosis, but want to ignore all zeros.
How can I do this?

Best Answer

out = cellfun(@(x)kurtosis(x(x~=0)),num2cell(A,1));
or
s = sum(A~=0);
x1 = bsxfun(@minus,A,sum(A)./s);
x1(A == 0) = 0;
out = s.*sum(x1.^4)./ sum(x1.^2).^2;