Path: news.mathworks.com!not-for-mail
From: "Donn Shull" <donn.shull.no_spam@aetoolbox.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to find elements of a given value in a matrix?
Date: Thu, 25 Dec 2008 19:44:02 +0000 (UTC)
Organization: L &#38; D Engineering LLC
Lines: 25
Message-ID: <gj0nq2$6b4$1@fred.mathworks.com>
References: <16525645.1230231468100.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "Donn Shull" <donn.shull.no_spam@aetoolbox.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1230234242 6500 172.30.248.37 (25 Dec 2008 19:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 25 Dec 2008 19:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 219306
Xref: news.mathworks.com comp.soft-sys.matlab:508764


juckou <ja79@hw.ac.uk> wrote in message <16525645.1230231468100.JavaMail.jakarta@nitrogen.mathforum.org>...
> Dear all,
> 
> I'm just trying to know how many elements in a matrix have a given value. I mean, if I have a matrix A=[1 2 3; 1 2 3; 1 2 3] I want to know the number (or the percentage) of elements that are "1" (3 or the 33,3% in this case).
> 
> Any help?
> Thank you very much
> 
> julio

Hello Julio,

You will want to use find and numel ie

>> percent = 100*(numel(find(A==2))/numel(A))

percent =

   33.3333

Good Luck,

Donn