Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Finding and Replacing Consecutive Numbers in an Array Date: Thu, 31 Mar 2011 22:12:02 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 28 Message-ID: <in2u7i$9ir$1@fred.mathworks.com> References: <imvasa$gbb$1@fred.mathworks.com> <in2kd4$jak$1@fred.mathworks.com> <in2s7s$7af$1@fred.mathworks.com> <in2tf9$qc7$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-00-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1301609522 9819 172.30.248.45 (31 Mar 2011 22:12:02 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 31 Mar 2011 22:12:02 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2799711 Xref: news.mathworks.com comp.soft-sys.matlab:719420 "Roger Stafford" wrote in message <in2tf9$qc7$1@fred.mathworks.com>... > "Florin Neacsu" <fneacsu2@gmail.com> wrote in message <in2s7s$7af$1@fred.mathworks.com>... > > Dear Roger, > > > > What if X = [1 1 1 1 1 3 3 3 3 3 3 3 0 0 2 2 2] ? The code you suggest yields > > > > X = 1 1 1 1 1 3 3 3 3 3 3 3 3 3 0 0 0 > > > > Is that what OP wants ? I understand that runs of consecutive numbers should be changed (with the condition of length<5) but in this example there are not consecutive numbers, so nothing should be changer. Am I misunderstanding ? > > > > Regards, > > Florin > - - - - - - - - - > It is true that Ern said, "runs of consecutive numbers", but I assumed he really meant "consecutive sequences of equal numbers". His example with: > > "X = [1 1 1 1 1 0 0 3 3 3 3 3 2 2 2 1 1] > I want the code to detect that there is a run of two zeros following a run of five 1s. The code would then replace the two zeros with 1s. It would then see that there are five 3's followed by three 2s, so the 2s would be replaced by 3s. Following that are two 1s, which in turn would be replaced by 3s." > > appears to bear that out, except that I would expect the last two ones to be replaced by twos, not threes. > > Roger Stafford Hello, I agree that the last substitution is ambigous. Maybe he/she will post an elucidator example. Regards, Florin