Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: goto, again
Date: Thu, 26 Jun 2008 11:07:01 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 80
Message-ID: <g3vt8l$r5h$1@fred.mathworks.com>
References: <g3vjsl$asv$1@fred.mathworks.com> <g3vl26$khl$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.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 1214478421 27825 172.30.248.38 (26 Jun 2008 11:07:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 26 Jun 2008 11:07:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:475938


"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