Technical discussion about Matlab and issues related to Digital Signal Processing.
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
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 >
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 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
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