Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet

Discussion Groups

Discussion Groups | Matlab DSP | Array 'x' might be grown using indexing. Consider preallocating for speed

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

Array 'x' might be grown using indexing. Consider preallocating for speed - #ARIJIT BISWAS# - Mar 19 15:49:34 2008



Hi all!

Consider this example:

x=[];
for i=1:1000
  x(i)=sin(i);
end

Here, M-Lint will tell you:
Array 'x' might be grown using indexing. Consider preallocating for speed.

How do I solve this?

Regards,
Arijit



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Array 'x' might be grown using indexing. Consider preallocating for speed - Nandan Das - Mar 20 8:52:34 2008

to accomplish what you are trying to do, you don't need a for loop.

x = sin(1:1000);  does it.

In general, what M-Lint is telling you is that you should declare x to be a
vector of size 1000
before you run it through the for-loop.  That will make the loop go faster.
so, e.g. you could have said, x = zeros(1000,1);  this declares x to be a
vector of length 1000
filled with zeros.

On Wed, Mar 19, 2008 at 3:53 AM, #ARIJIT BISWAS# <a...@pmail.ntu.edu.sg>
wrote:

> Hi all!
>
> Consider this example:
>
> x=[];
> for i=1:1000
>  x(i)=sin(i);
> end
>
> Here, M-Lint will tell you:
> Array 'x' might be grown using indexing. Consider preallocating for speed.
>
> How do I solve this?
>
> Regards,
> Arijit
>



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Array 'x' might be grown using indexing. Consider preallocating for speed - loc truong - Mar 20 8:52:36 2008

Hi,

that is just a warning because you didn't initialize the size of variable x.
Just do x = zeros(1,100) to define the size of variable x before giving the values.

Best Regards,

Kenny

----- Original Message ----
From: #ARIJIT BISWAS# <a...@pmail.ntu.edu.sg>
To: m...@yahoogroups.com
Sent: Wednesday, March 19, 2008 11:53:14 AM
Subject: [matlab] Array 'x' might be grown using indexing. Consider preallocating for speed

                Hi all!

Consider this example:

x=[];
for i=1:1000
  x(i)=sin(i);
end

Here, M-Lint will tell you:
Array 'x' might be grown using indexing. Consider preallocating for speed.

How do I solve this?

Regards,
Arijit



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

RE: Array 'x' might be grown using indexing. Consider preallocating for speed - Ahmad El-Saeed - Mar 20 8:52:48 2008

You may try this:

x=zeros(1,1000);

for i=1:1000

x(i)=sin(i);

end

this is not an error by the way .. it is a hint to speed up your script !!

Regards,

Ahmad

  _____  

From: m...@yahoogroups.com [mailto:m...@yahoogroups.com] On Behalf Of
#ARIJIT BISWAS#
Sent: Wednesday, March 19, 2008 12:53 PM
To: m...@yahoogroups.com
Subject: [matlab] Array 'x' might be grown using indexing. Consider
preallocating for speed

Hi all!

Consider this example:

x=[];
for i=1:1000
x(i)=sin(i);
end

Here, M-Lint will tell you:
Array 'x' might be grown using indexing. Consider preallocating for speed.

How do I solve this?

Regards,
Arijit



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

RE: Array 'x' might be grown using indexing. Consider preallocating for speed - #ARIJIT BISWAS# - Mar 20 8:54:02 2008

Thanks a lot guys, for tips n tricks.

Regards,
Arijit

-----Original Message-----
From: Jaganathan Gnanavelu [mailto:p...@yahoo.com]
Sent: Thu 3/20/2008 9:28 AM
To: #ARIJIT BISWAS#
Subject: Re: [matlab] Array 'x' might be grown using indexing. Consider preallocating for
speed
 
arijit,
  Try this
  x = [];
  for i=1:1000,
  x = [x sin(i)]
end
   
  Regards,
  Jaganathan
  j...@ieee.org
  
#ARIJIT BISWAS# <a...@pmail.ntu.edu.sg> wrote:
          Hi all!

Consider this example:

x=[];
for i=1:1000
x(i)=sin(i);
end

Here, M-Lint will tell you:
Array 'x' might be grown using indexing. Consider preallocating for speed.

How do I solve this?

Regards,
Arijit



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )