Prev: How do you make an unavailabe COM port available?
Next: Returning a specified iteration from iterative solvers such as bicgstab
From: Joseph on 14 May 2010 17:08 I understand that typically "vectorizing" and removing for-loops makes Matlab code (within Matlab, I'm not talking about compiling/hand-converting to C, C++, etc.) faster inside the Matlab application. However, I have successfully "vectorized" some code involving "cell arrays" and it appears not to be significantly faster, it even may be somewhat slower. Is this to be anticipated? Is there a general paradigm for speeding up cell array operations? Is a double-for loop the best way to do this? Thanks, Sincerely, Joseph PhD and Matlab "expert"
From: Bruno Luong on 14 May 2010 17:15 "Joseph " <josephamarks(a)yahoo.com> wrote in message <hske3k$ea8$1(a)fred.mathworks.com>... > I understand that typically "vectorizing" and removing for-loops makes Matlab code (within Matlab, I'm not talking about compiling/hand-converting to C, C++, etc.) > faster inside the Matlab application. > > However, I have successfully "vectorized" some code involving "cell arrays" and it appears not to be significantly faster, it even may be somewhat slower. > > Is this to be anticipated? > Yes, cell array (and structure) operation is always slow, no matter what you do. Bruno
From: Jan Simon on 14 May 2010 17:19 Dear Joseph! > I understand that typically "vectorizing" and removing for-loops makes Matlab code (within Matlab, I'm not talking about compiling/hand-converting to C, C++, etc.) > faster inside the Matlab application. > > However, I have successfully "vectorized" some code involving "cell arrays" and it appears not to be significantly faster, it even may be somewhat slower. > > Is this to be anticipated? > > Is there a general paradigm for speeding up cell array operations? > Is a double-for loop the best way to do this? This is a very general question. The answer depends on the special case. If you search for a string in a cell, a vectorized call to STRCMP will be much faster than two for loop. A vectorized call with CELLFUN(@strmatch, ...) might be much slower than two for loops. Jan
From: Joseph on 14 May 2010 17:25 Just saying thanks for replying. If anyone does know a way to speed up cell arrays, please post. Thanks, Bruno for honesty. Sometimes in a situation like this, people try to "hide" the data ....
From: Joseph on 14 May 2010 17:32
Dear Jan! Thanks. In my specific example, I'm talking about simple storing/fetching data to/from a cell array. Consider storing data in a cell array with a double-for loop, thusly: count = 0 for j = 1: n for i = 1:m count = count+1; B{count,1} = {d{j}, ei}, F(i,j) }; end end To be honest, I still don't quite naturally "get" the difference between {} and () in these cell operations, but I digress. From someone else's blog, I understand that curly means content ... In any event, I vectorized the problem successfully, but it really didn't speed things up. My question is, is this to be expected? {I think Bruno would say yes, Jan maybe would say maybe} Thanks Again! "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hskeo9$rsd$1(a)fred.mathworks.com>... > Dear Joseph! > > > I understand that typically "vectorizing" and removing for-loops makes Matlab code (within Matlab, I'm not talking about compiling/hand-converting to C, C++, etc.) > > faster inside the Matlab application. > > > > However, I have successfully "vectorized" some code involving "cell arrays" and it appears not to be significantly faster, it even may be somewhat slower. > > > > Is this to be anticipated? > > > > Is there a general paradigm for speeding up cell array operations? > > Is a double-for loop the best way to do this? > > This is a very general question. The answer depends on the special case. > If you search for a string in a cell, a vectorized call to STRCMP will be much faster than two for loop. A vectorized call with CELLFUN(@strmatch, ...) might be much slower than two for loops. > > Jan |