Path: news.mathworks.com!not-for-mail
From: "Ashish Uthama" <first.last@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: count number of 1's in the matrix
Date: Tue, 30 Jun 2009 17:32:42 -0400
Organization: TMW
Lines: 21
Message-ID: <op.uwcwssi0a5ziv5@uthamaa.dhcp.mathworks.com>
References: <h2dspt$pgv$1@fred.mathworks.com>
 <cd387b6b-ba68-4100-8218-a03d69c844de@k15g2000yqc.googlegroups.com>
 <h2dtvd$cg1$1@fred.mathworks.com>
NNTP-Posting-Host: uthamaa.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1246397562 16054 172.31.57.126 (30 Jun 2009 21:32:42 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 30 Jun 2009 21:32:42 +0000 (UTC)
User-Agent: Opera Mail/9.63 (Win32)
Xref: news.mathworks.com comp.soft-sys.matlab:551844


On Tue, 30 Jun 2009 16:53:01 -0400, Bruno Luong  
<b.luong@fogale.findmycountry> wrote:

> nnz(A)
>
> Bruno

%as noted earlier, SUM works only for 1/0 matrices

>> d=double(rand(5010)>.5);
>> timeit(@()nnz(d))

ans =

       0.13992

>> timeit(@()sum(sum(d)))

ans =

      0.031067