Prev: XlimMode = 'manual' overridden by subsequent plot?
Next: Analysis of data set - autocorrelation
From: Hugo on 15 Jun 2010 11:33 Hi. To run my program, I need to create objects iteratively... This is what I have done: for i=1:100 r(i)=RSpectrum(...) end where "RSpectrum" is the class used to build each r object and "..." are the required inputs. However, I do not know how I can allocate memory for r. Can anyone help me out? Many thanks in advance.
From: Sunny on 15 Jun 2010 11:47 "Hugo " <hresquiveloa(a)gmail.com> wrote in message <hv86g0$b8b$1(a)fred.mathworks.com>... > Hi. To run my program, I need to create objects iteratively... This is what I have done: > > for i=1:100 > r(i)=RSpectrum(...) > end > > where "RSpectrum" is the class used to build each r object and "..." are the required inputs. > > However, I do not know how I can allocate memory for r. Can anyone help me out? > > Many thanks in advance. Hi Hugo, To do this, you need to allocate rows and columns for the element "r". try: for i = 1:100 r(i,:) = Rspectrum(...) end Or a variation of such
From: Hugo on 15 Jun 2010 12:00 Sunny, Thanks for reply... My objects are: r(1), r(2), r(3), ..., r(100) But I need to find a way to preallocate r before treating to create them inside the loop. Do you know how can I do it?
From: Sunny on 15 Jun 2010 12:10 "Hugo " <hresquiveloa(a)gmail.com> wrote in message <hv882o$nq8$1(a)fred.mathworks.com>... > Sunny, > > Thanks for reply... > > My objects are: > r(1), r(2), r(3), ..., r(100) > > But I need to find a way to preallocate r before treating to create them inside the loop. Do you know how can I do it? Yes, You can pre-allocate memory by creating a vector or matrix of zeros before your loop. This will speed up the time of the loop For example: r =zeros(1,100) ; %gives a 1x100 vector of 0 for i=1:100 %loop here end Cheers
From: Walter Roberson on 15 Jun 2010 12:16 Sunny wrote: > "Hugo " <hresquiveloa(a)gmail.com> wrote in message > <hv882o$nq8$1(a)fred.mathworks.com>... >> Sunny, >> >> Thanks for reply... >> >> My objects are: >> r(1), r(2), r(3), ..., r(100) >> >> But I need to find a way to preallocate r before treating to create >> them inside the loop. Do you know how can I do it? > > Yes, > You can pre-allocate memory by creating a vector or matrix of zeros > before your loop. This will speed up the time of the loop > > For example: > > r =zeros(1,100) ; %gives a 1x100 vector of 0 > > for i=1:100 > %loop here > end Sunny, you are missing the point that each r is an _object_, not a double. Hugo, the quick way to allocate would be to calculate r(100) first and then to fill in r(1) through r(99) . If I recall correctly there are examples of constructing arrays of objects. I have never worked with that myself, so I do not recall the technique.
|
Next
|
Last
Pages: 1 2 Prev: XlimMode = 'manual' overridden by subsequent plot? Next: Analysis of data set - autocorrelation |