From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: very large array
Date: Mon, 24 Jun 2013 11:13:24 -0500
Organization: NNTP Server
Lines: 59
Message-ID: <kq9r5n$21t$>
References: <kq9hdf$bsa$> <kq9khs$kvi$> <kq9n1f$smu$> <kq9nib$12h$>
NNTP-Posting-Host: jy+QfeYoQFMk8Or4YOj/
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: comp.soft-sys.matlab:798117

On 6/24/2013 10:11 AM, Lorenzo Quadri wrote:
> "Lorenzo Quadri" <> wrote in message
> <kq9n1f$smu$>...
>> "Steven_Lord" <> wrote in message > > Not only will
>> this be slow, it will also error. If you have a 10 row array:
>> you'd walk off the end of the array if any of the rows are deleted.

>> I replaced the for loop with a while one like:
>> a=length(dati)
>> while (a>0)
>>   if((sum(dati(i,:))<355) & range(dati(i,:))>20)
>>     a = a - 1;
>>     dati(i,:) = [];
>>   end
>> end
>> I'll try evaluate it with logical indexing as you suggested.
>> Copy the array in an other one take about 1,5 hrs every 1000000
>> iterations
>> so the whole operation is exstimated in about 300 hrs or 12,5 days
>> (too much, conditions change meanwhile).
>> thank you very much
> ops sorry
> while (a>0)
>   if((sum(dati(i,:))<355) & range(dati(i,:))>20)
>     dati(i,:) = [];
>   end
>   a = a - 1;
> end

Now you're not incrementing i so you'll process the same row over and 
over and over...

While doing it by a loop is _NOT_ the way for large cases, sometimes it 
is handy and time isn't an issue for small array sizes.  The way in 
general to do such things is to start at the end and progress 
forwards--that way the lower indices aren't affected by the deleted rows...

for i=length(dat):-1:1
   if((sum(dati(i,:))<355) & range(dati(i,:))>20)
     dati(i,:) = [];

Now it won't run off the end (but it will still run a _loooong_ time, 

See other comments on "why" and perhaps a more-quicker way of breaking 
it into chunks if you're causing memory paging w/ it in one full array 
in (virtual) memory.