Path: news.mathworks.com!not-for-mail
From: "Armando Ciccarelli" <damagedlemon@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: goto, again
Date: Thu, 26 Jun 2008 18:04:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 110
Message-ID: <g40lmh$bdc$1@fred.mathworks.com>
References: <g3vjsl$asv$1@fred.mathworks.com> <g3vl26$khl$1@fred.mathworks.com> <g3vt8l$r5h$1@fred.mathworks.com>
Reply-To: "Armando Ciccarelli" <damagedlemon@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1214503441 11692 172.30.248.38 (26 Jun 2008 18:04:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 26 Jun 2008 18:04:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1426197
Xref: news.mathworks.com comp.soft-sys.matlab:476067


"John D'Errico" <woodchips@rochester.rr.com> wrote in
message <g3vt8l$r5h$1@fred.mathworks.com>...
> "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
wrote in 
> message <g3vl26$khl$1@fred.mathworks.com>...
> > "Armando Ciccarelli" <damagedlemon@gmail.com> wrote in 
> > message <g3vjsl$asv$1@fred.mathworks.com>...
> > > I have this routine in Fortran
> > > 
> > > 
> > >       do m1=2,n
> > >          m1m(m1) = 1
> > >          do j=m1-1,2,-1
> > >             if (x(j).ne.x(j-1)) then
> > >                m1m(m1) = j
> > >                goto 441
> > >             endif
> > >          enddo
> > >  441     continue
> > >       enddo
> > > 
> > > that is part of a larger code.
> > > I converted it in Matlab as
> > > 
> > > for m1=2:n;
> > >     m1m(m1) = 1;
> > >     for j=m1-1:-1:2;
> > >         if(x(j)~=x(j-1)) ;
> > >             m1m(m1) = j;
> > >             continue;
> > >         end;
> > >     end;
> > > end;
> > > 
> > > of course the results are not the same, and this is due 
> > to 
> > > my inabilty to translate the goto function
> > > How can I solve this problem?
> > 
> > Use Matlab as designed.  Your double nested loop can 
> > probably be done with a single Matlab line.  If you state 
> > your original problem you may find some kind person shows 
> > you the light (I personally can't be arsed to plough 
> > through all that Fortran).
> > 
> > I have a matrix: x
> > I want to make a matrix m1m from it, based on the following 
> > rules.
> > 
> > For example, [......] would give [.......]
> 
> That was an example of Fortran code for which
> the author should be shot. It is what (rightfully
> so, IMHO) gave fortran such a bad name.
> 
> A complete lack of comments. Use of variable
> names like m1m and m1. goto. (shiver)
> 
> I find it interesting that Steve was unwilling to
> read through such a tiny code fragment. Bad
> code does this to you. The answer is truly to
> understand what the code does, and then to
> write that in Matlab, rather than perpetuating
> such a poorly written piece of code. Had the
> code actually had comments that explained
> the purpose of this fragment, this might have
> been much simpler.
> 
> Ok, I'm through venting.
> 
> set('JohnsRoot','RantMode','off')
> 
> The outer loop looks at each element of x,
> sequentially, from the second to the end.
> The inner loop finds the first index, working
> backwards, such that x(j) ~= x(j-1).
> 
> So you might figure out how to do this, or
> perhaps figure out why the author is trying
> to form this result in the first place. Or you
> can just use break instead of continue.
> 
> John


break instead of continue stops the inner loop, while the
option in the fortran code allows to exit both of the two loops.

i tried using break

what i get is a vector which has zero as first value, one as
second, then it takes the value of j such that x(j) and
x(j-1) are different: the value is carried over the
following elements of the vector until the inner cicle
doesn't find another value j such that x(j) and x(j-1) are
different: at this point the procedures begins again...

so it goes like

[0 1 2 2 2 2 2 3 3 3 3 3 3 4 4 4 10 10 10...], something
like that...

i am trying to understand, and i think this was the actual
intention of the author,wheter instead the vector should be
something like:

[0 1 2 1 1 1 1 3 1 1 1 1 1 4 1 1 10 1 1...], so that the
value j st x(j) doesnt equal x(j-1) is not carried over...

hope i made myself clear