Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!llnews!53ab2750!not-for-mail
From: Peter Boettcher <boettcher@ll.mit.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How can I make these lines shorter?
References: <gp295g$dn1$1@fred.mathworks.com>
	<gp29vp$737$1@fred.mathworks.com> <gp2bq0$500$1@fred.mathworks.com>
	<gp2d52$1ug$1@fred.mathworks.com>
Message-ID: <muyd4cqlk2d.fsf@G99-Boettcher.llan.ll.mit.edu>
Organization: MIT Lincoln Laboratory
User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/23.0.0 (gnu/linux)
Cancel-Lock: sha1:wRazdXUe4BYkwt7FSpgqt0ikTw0=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 50
Date: Mon, 09 Mar 2009 12:47:38 -0400
NNTP-Posting-Host: 155.34.163.93
X-Complaints-To: news@ll.mit.edu
X-Trace: llnews 1236617258 155.34.163.93 (Mon, 09 Mar 2009 12:47:38 EDT)
NNTP-Posting-Date: Mon, 09 Mar 2009 12:47:38 EDT
Xref: news.mathworks.com comp.soft-sys.matlab:523522


"Husam Aldahiyat" <numandina@gmail.com> writes:

> "Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <gp2bq0$500$1@fred.mathworks.com>...
>> My apologies for multiple posts. I'm getting load errors for every page.
>> 
>> Try the following
>> ~abs(sign(round(diff([con(1),con(3)])))) the same as isequal(con(1),con(3))
>> and
>> ~(~(sum(ismember(diff(con),1)))) the same as any(diff(con)==1)
>> Hth
>> Darren
>
> Thanks! 
> The first was really a test to see if they were equal but I missed the function isequal. 
>
> The second was a test if the diff was 1. Also present in the algorithm
> is another test if diff was 2 so I'll use any(diff(con)==2).
>
> Thanks for the help.

Other general advice:

Since these are scalars, == is even better than isequal.  Your first
expression is simply

con(1)==con(3)

And if you need to negate it, use con(1)~=con(3)

I think you'll find that the ~(~(con(3)-con(2)-2)) expressions are also
better written using equalities: con(3)~=con(2)+2

round does nothing when all the inputs are integers.

After you've gone through and done all these simplifications, post back
again.  Other stuff might be clearer at that point.

Depending on what all this means, you might actually think about
specifying the whole thing as a look-up table.  Right now the code means
nothing to me, so a look-up table makes just as much sense:

sign2(1,1,1) = 1;
sign2(1,1,2) = -1;

Etc.

Then just look up your answer with sign2(con(1),con(2),con(3))


-Peter