Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe07.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to find elements of a given value in a matrix?
References: <16525645.1230231468100.JavaMail.jakarta@nitrogen.mathforum.org>
In-Reply-To: <16525645.1230231468100.JavaMail.jakarta@nitrogen.mathforum.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 15
Message-ID: <bOe6l.26641$wV2.14471@newsfe07.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe07.iad 1230600455 24.79.146.116 (Tue, 30 Dec 2008 01:27:35 UTC)
NNTP-Posting-Date: Tue, 30 Dec 2008 01:27:35 UTC
Date: Mon, 29 Dec 2008 19:27:32 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:509168


juckou wrote:

> 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).

Others have recommended find. An alternative is:
sum(A(:)==1) / numels(A)
which should be faster than find()

-- 
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?