Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to find elements of a given value in a matrix?
Date: Tue, 30 Dec 2008 08:46:01 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 25
Message-ID: <gjcn49$pfi$1@fred.mathworks.com>
References: <16525645.1230231468100.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1230626761 26098 172.30.248.38 (30 Dec 2008 08:46:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 30 Dec 2008 08:46:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:509192


juckou
> I'm just trying to know how many elements in a matrix have a given value...

one of the many solutions

% the data
     m=[
          1 -2 pi
          -2 1 -1
          1 1 pi
     ];
% the engine
     [mu,mx,mx]=unique(m(:));
     r=accumarray(mx,m(:),[],@numel);
     rp=100*r./numel(m);
% the result
     disp([mu,r,rp]);
%{
          -2                2       22.222
          -1                1       11.111
           1                4       44.444
           3.1416           2       22.222
%}

us