Thread Subject: sparsing 3-D array

Subject: sparsing 3-D array

From: Theodor Zouk

Date: 4 Dec, 2008 10:16:03

Message: 1 of 3

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
  

Subject: sparsing 3-D array

From: Jos

Date: 4 Dec, 2008 10:29:02

Message: 2 of 3

"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

Subject: sparsing 3-D array

From: Theodor Zouk

Date: 4 Dec, 2008 12:58:02

Message: 3 of 3

"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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com