MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayNew to MATLAB?
MATLAB Central > MATLAB Newsreader > Highdimensional sparse array ?? 

Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 9 Dec, 2010 12:26:05 Message: 1 of 33 
Hi all, 
Subject: Highdimensional sparse array ?? From: Bruno Luong Date: 9 Dec, 2010 12:41:04 Message: 2 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <idqhst$mo7$1@ginger.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 9 Dec, 2010 12:52:05 Message: 3 of 33 
Gosh that sounds like an important Matlab limitation !! Also, and this is related to my previous question, is there a way to call a function to act only on the nonzero matrix elements of an array ? This would save me a lot of time and memory as for the moment I call my function (say Func) as Func(M) where M is my highdimensional array, but then I discard the results of Func(M) where M was 0. So can I have Func to act only on nonzero elements of M? 
Subject: Highdimensional sparse array ?? From: Loren Shure Date: 9 Dec, 2010 12:54:06 Message: 4 of 33 

Subject: Highdimensional sparse array ?? From: Bruno Luong Date: 9 Dec, 2010 13:04:05 Message: 5 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <idqjdl$jpo$1@ginger.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 9 Dec, 2010 13:08:04 Message: 6 of 33 
But spfun works for sparse matrices and the point is my array cannot be put into sparse form since it is highdimensional... 
Subject: Highdimensional sparse array ?? From: James Tursa Date: 9 Dec, 2010 16:04:04 Message: 7 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <idqkbk$1ho$1@fred.mathworks.com>... 
If you want to take an object oriented approach, below (bottom of post) is a rudimentary classdef to get you started. 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 9 Dec, 2010 17:50:25 Message: 9 of 33 
"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <idqulk$hip$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: James Tursa Date: 9 Dec, 2010 19:45:24 Message: 10 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <idr4t1$ess$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 9 Dec, 2010 22:33:05 Message: 11 of 33 
My arrays have up to 10 dimensions and each dimension can be up to a hundred elements, although because of memory considerations when I have 10 D I limit each dimension size to a smaller number. 
Subject: Highdimensional sparse array ?? From: Matt J Date: 27 Dec, 2010 15:29:05 Message: 12 of 33 
"Matt J" wrote in message <idqva9$bh$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 11 Jan, 2011 13:33:05 Message: 13 of 33 
Thanks a lot that looks amazing, I will test it thoroughly but anyway I think you really filled a big hole in Matlab's possibilities. 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 11 Jan, 2011 13:41:05 Message: 14 of 33 
ndstest does not work as it is, Matlab says : 
Subject: Highdimensional sparse array ?? From: Matt J Date: 11 Jan, 2011 14:29:04 Message: 15 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <ighmlh$s7l$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 11 Jan, 2011 14:50:20 Message: 16 of 33 
Thank you for your quick reply. I updated my version to R2010b and everything works fine now. Your program is great and seems to work in my computations so far ! What a memory saving code !! 
Subject: Highdimensional sparse array ?? From: Matt J Date: 11 Jan, 2011 14:59:06 Message: 17 of 33 
"Matt J" wrote in message <ighpfg$t2s$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 11 Jan, 2011 15:09:05 Message: 18 of 33 
Strange bug indeed. On my computer here is what I have : 
Subject: Highdimensional sparse array ?? From: Matt J Date: 11 Jan, 2011 15:57:06 Message: 19 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <ighrqh$394$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Matt J Date: 11 Jan, 2011 16:58:06 Message: 20 of 33 
"Matt J" wrote in message <ighuki$4sv$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 11 Jan, 2011 17:09:21 Message: 21 of 33 
Thanks that function is a good complement to the ndSparse class. 
Subject: Highdimensional sparse array ?? From: Matt J Date: 11 Jan, 2011 18:45:05 Message: 22 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <igi2s1$8ln$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Matt J Date: 11 Jan, 2011 18:55:06 Message: 23 of 33 
"Matt J" wrote in message <igi8fh$9ok$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Matt J Date: 11 Jan, 2011 19:02:06 Message: 24 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <igi2s1$8ln$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 11 Jan, 2011 20:10:05 Message: 25 of 33 
Yes it is thus all the more surprising that my computation originally took 50 sec with full arrays but now takes 350sec with sparse arrays. I will try with harder computations (i.e. originally longer) to see how this scales with the array size. 
Subject: Highdimensional sparse array ?? From: Bruno Luong Date: 11 Jan, 2011 20:25:05 Message: 26 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <igidet$2gr$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 12 Jan, 2011 10:45:05 Message: 27 of 33 
I used the profiler to see what was taking time. Clearly the time consumption is concentrated in 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 12 Jan, 2011 11:20:06 Message: 28 of 33 
Here is the profiler detailed result about ndSparse.time 
Subject: Highdimensional sparse array ?? From: Matt J Date: 12 Jan, 2011 14:54:05 Message: 29 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <igk2p5$j5p$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Pier Ferd Date: 12 Jan, 2011 15:12:04 Message: 30 of 33 
This is an interesting remark, but my code has absolutely no For loops nor any While. Is it possible that my code has some sort of loop then from another function ? 
Subject: Highdimensional sparse array ?? From: Matt J Date: 12 Jan, 2011 15:46:04 Message: 31 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <igkgc4$cvo$1@fred.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Iain Strachan Date: 22 Jan, 2013 12:40:08 Message: 32 of 33 
"Pier Ferd" <plg255@hotmail.com> wrote in message <idqhst$mo7$1@ginger.mathworks.com>... 
Subject: Highdimensional sparse array ?? From: Matt J Date: 22 Jan, 2013 14:48:09 Message: 33 of 33 
"Iain Strachan" wrote in message <kdm1b8$cso$1@newscl01ah.mathworks.com>... 
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.