Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!k15g2000yqc.googlegroups.com!not-for-mail
From: Nathan <ngreco32@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: count number of 1's in the matrix
Date: Tue, 30 Jun 2009 13:38:07 -0700 (PDT)
Organization: http://groups.google.com
Lines: 11
Message-ID: <cd387b6b-ba68-4100-8218-a03d69c844de@k15g2000yqc.googlegroups.com>
References: <h2dspt$pgv$1@fred.mathworks.com>
NNTP-Posting-Host: 198.206.219.33
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1246394287 6771 127.0.0.1 (30 Jun 2009 20:38:07 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 30 Jun 2009 20:38:07 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: k15g2000yqc.googlegroups.com; posting-host=198.206.219.33; 
	posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) 
	Gecko/20090624 Firefox/3.5,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 wwwproxy-son-ca-01.ca.sandia.gov:80 (squid/2.5.STABLE14)
Xref: news.mathworks.com comp.soft-sys.matlab:551826


On Jun 30, 1:33 pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> Hi
> I have a matrix with 0's, 1's.  I want to count the number of 1's.
> A = [1 0 0 0 1 0; 1 0 0 0 1 1; 0 0 0 0 1 1]
>
> What is the most efficient way of doing this?
> Thanks
> Diego

I'd just do:
count = sum(sum(A));