Path: news.mathworks.com!not-for-mail
From: "Tim Davis" <davis@cise.ufl.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: deleting 0s from an array
Date: Fri, 17 Aug 2007 16:14:22 +0000 (UTC)
Organization: University of Florida
Lines: 21
Message-ID: <fa4hgt$qgn$1@fred.mathworks.com>
References: <fa07po$f1c$1@fred.mathworks.com> <fa08s1$r4b$1@fred.mathworks.com> <1187326130.279914.104760@g12g2000prg.googlegroups.com> <fa3kot$4mp$1@fred.mathworks.com> <fa3n8c$1an$1@canopus.cc.umanitoba.ca> <fa3p6t$mn1$1@fred.mathworks.com>
Reply-To: "Tim Davis" <davis@cise.ufl.edu>
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 1187367262 27159 172.30.248.37 (17 Aug 2007 16:14:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 17 Aug 2007 16:14:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 45902
Xref: news.mathworks.com comp.soft-sys.matlab:424323


"Tim Davis" <davis@cise.ufl.edu> wrote in message 
> Then if you want the location information, use find(d).  You
> can't use find(d) with the other solutions.
> 

Umm.  I guess my brain is too sparse.  I should have
mentioned that to use find(d) you would do

[i j x] = find(d)

then x is the vector you're looking for, with zeros deleted,
and i is the list of d(i)'s that are nonzero (assuming d is
a column vector).

The above works if d is full or sparse; you don't have to do

d = sparse (d) 

first.  I think the above is really the simplest way to do
it, personally.  But then I'm used to seeing "find"
statements flying around in m-files.