Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Loop Question
Date: Fri, 6 Feb 2009 00:59:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 16
Message-ID: <gmg20l$hek$1@fred.mathworks.com>
References: <gmfvpd$26v$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1233881941 17876 172.30.248.37 (6 Feb 2009 00:59:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 6 Feb 2009 00:59:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:516495

"Garrett " <bantong@onid.orst.edu> wrote in message <gmfvpd$26v$1@fred.mathworks.com>...
> Hi,
> 
> I have a for loop that has an index from 1: length(y) where y is a previously defined Nx1 array. The problem I am having is the search that i run in the for loop finds data that contains multiple points on y at a time. I need to delete these points on y before the for loop cycles again to avoid duplicate data. Obviously this leads to a bit of a paradox because the higher index length(y) is getting shorter every cycle. I was wondering if anyone had an idea of how to stop the loop before it exceeds its index.
> 
> Thanks,
> 
> -Garrett

  It's hard to give you a valid suggestion without understanding the nature of your procedure.  What you describe seems fraught with dangerous possibilities.  Your for-loop generates an index which presumably refers to the y-values.  What are you supposed to do when the index arrives at a place where the y has already been slated for deletion?  Are you allowed to refer to it anyway?  Also if you carry out the deletions in y as you go along, that breaks the connection between your index and the proper location in y.  I would say you need to accumulate in a vector the indices of y's you want deleted but postpone the actual deletion until your looping is finished, at which time you can use this vector to delete them all at the same time.

  You still are faced with the problem of what to do with for-loop indices that are for y's that have already been scheduled for deletion.  Perhaps you need a test for these so you can skip to the next iteration of the loop.

  You would have been well-advised to give more information about what is supposed to happen within your loop and the logic of how you decide which y's are to be deleted.

Roger Stafford