An alternative solution: n=10; M= bool2s(rand(n,n)>0.5); // Boolean to zero-ones matrix A= rand(n,n); x= sum(A.*M,'r') ./ sum(M,'r'); Regards, Rafael -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.scilab.org/pipermail/users/attachments/20180303/c1ae4710/attachment.htm>