Path: news.mathworks.com!not-for-mail
From: "Theodor Zouk" <rebet4@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sparsing 3-D array
Date: Thu, 4 Dec 2008 12:58:02 +0000 (UTC)
Organization: Univ of Umea
Lines: 26
Message-ID: <gh8k4q$9ld$1@fred.mathworks.com>
References: <gh8al2$480$1@fred.mathworks.com> <gh8bde$cba$1@fred.mathworks.com>
Reply-To: "Theodor Zouk" <rebet4@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228395482 9901 172.30.248.35 (4 Dec 2008 12:58:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Dec 2008 12:58:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1540208
Xref: news.mathworks.com comp.soft-sys.matlab:504950


"Jos " <#10584@fileexchange.com> wrote in message <gh8bde$cba$1@fred.mathworks.com>...
> "Theodor Zouk" <rebet4@hotmail.com> wrote in message <gh8al2$480$1@fred.mathworks.com>...
> > Hi
> > 
> > Is there any function in matlab that can sparse arrays with a higher dimension than 2?
> > 
> > What i have is a mulstidimension array that is 256x256x256 elements long. Now, Im know that 4096 of these entries have an value and the rest has the value of zero (= a hell of a lot of zeros =). This multidim array ("cube") is used in a loop where this array is added,subtracted,multiplied elementwise with other multidim arrays also constisting of a lot of zeros. The 4096 entries can be different from each iteration.
> > I think that i will gain some execution speed if i can sparse these multidim arrays and then "eliminate" the calculations over the zeros value entries (elements)...
> > 
> > regards
> > 
> > Theo 
> >   
> 
> Make your ND arrays a long column vector. When the need arises for getting the row/column/plane indices of the non-zero entries, use IND2SUB. Example
> 
> sz = size(NDarray) ;
> B = sparse(NDarray(:)) ;
> B = B + 1 ; 
> [subi{1:numel(sz)}] = IND2SUB(sz,find(B))
> 
> hth
> Jos

ok, thanks for the help Jos
/theo