help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lists vs cell arrays


From: Bertrand Roessli
Subject: Re: lists vs cell arrays
Date: Wed, 22 Aug 2007 11:15:29 +0200

Yes, it is much faster, thanks, but the loop is still quicker.

tic;
[cell2mat(moment_cell).rm].*cos([cell2mat(moment_cell).rtheta]/180*pi);
toc

  Elapsed time is 0.030724 seconds


tic;
[[moment_cell{:}].rm].*cos([[moment_cell{:}].rtheta]/180*pi);
toc
   Elapsed time is 0.001862 seconds.


tic;
for i=1:columns(moment_cell)
  moment_cell{i}.rm.*cos(moment_cell{i}.rtheta/180*pi);
endfor
toc   
  Elapsed time is 0.000465 seconds.



On Wed, 2007-08-22 at 10:48 +0200, Michael Goffioul wrote:
> On 8/22/07, Bertrand Roessli <address@hidden> wrote:
> > Hello,
> >
> > Because 'lists' are deprecated in Octave and not implemented in Matlab,
> > I am trying to replace all the 'lists' by 'cell' and also to vectorise
> > the code as much as possible.
> >
> > However, comparison of the following pieces of code
> >
> > tic;
> > [cell2mat(moment_cell).rm].*cos([cell2mat(moment_cell).rtheta]/180*pi);
> > toc
> >
> > tic;
> > for i=1:nth(moment_list,1)
> >        nth(moment_list,i+1).rm*cos(nth(moment_list,i+1).rtheta/180*pi);
> > endfor
> > toc
> >
> > yields
> >
> > Elapsed time is 0.044952 seconds.
> > and
> > Elapsed time is 0.000488 seconds.
> >
> > (Octave 2.9.9)
> >
> > Is there a way to 'accelerate' [cell2mat]?
> 
> I don't know if it will be faster, but what about:
> 
> [moment_cell{:}]
> 
> to create the structure array.
> 
> Michael.
-- 
Dr. Bertrand Roessli
Laboratory for Neutron Scattering
Paul Scherrer Institut and ETH Zurich
CH-5232 Villigen PSI

Tel.: +41 56 310 44 01



reply via email to

[Prev in Thread] Current Thread [Next in Thread]