<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190</link>
    <title>MATLAB Central Newsreader - How can I make these lines shorter?</title>
    <description>Feed for thread: How can I make these lines shorter?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 09 Mar 2009 05:24:00 -0400</pubDate>
      <title>How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#633410</link>
      <author>Husam Aldahiyat</author>
      <description>Hello,&lt;br&gt;
I created an algorithm and everything works fine, but there are line that I think can be made shorter using a command or technique I don't know about. Here are the lines:&lt;br&gt;
&lt;br&gt;
sign2=round(((~abs(sign(round(diff([con(1),con(3)])))))*(-2*((~(~(con(3)-con(2)+1)))*...&lt;br&gt;
(~(~(con(3)-con(2)-2))))+1))+~(~abs(sign(round(diff([con(1),con(3)]))))));&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
sign1=round(~(~abs(sign(round(diff([con(1),con(3)])))))*...&lt;br&gt;
	-2*(~(~(sum(ismember(diff(con),1)))))+1);</description>
    </item>
    <item>
      <pubDate>Mon, 09 Mar 2009 05:30:04 -0400</pubDate>
      <title>Re: How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#633412</link>
      <author>Husam Aldahiyat</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gp295g$dn1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; I created an algorithm and everything works fine, but there are line that I think can be made shorter using a command or technique I don't know about. Here are the lines:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign2=round(((~abs(sign(round(diff([con(1),con(3)])))))*(-2*((~(~(con(3)-con(2)+1)))*...&lt;br&gt;
&amp;gt; (~(~(con(3)-con(2)-2))))+1))+~(~abs(sign(round(diff([con(1),con(3)]))))));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign1=round(~(~abs(sign(round(diff([con(1),con(3)])))))*...&lt;br&gt;
&amp;gt; 	-2*(~(~(sum(ismember(diff(con),1)))))+1);&lt;br&gt;
&lt;br&gt;
con is a three element vector with each element having a value of 1, 2 or 3.</description>
    </item>
    <item>
      <pubDate>Mon, 09 Mar 2009 05:38:01 -0400</pubDate>
      <title>Re: How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#633413</link>
      <author>Darren Rowland</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gp295g$dn1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; I created an algorithm and everything works fine, but there are line that I think can be made shorter using a command or technique I don't know about. Here are the lines:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign2=round(((~abs(sign(round(diff([con(1),con(3)])))))*(-2*((~(~(con(3)-con(2)+1)))*...&lt;br&gt;
&amp;gt; (~(~(con(3)-con(2)-2))))+1))+~(~abs(sign(round(diff([con(1),con(3)]))))));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign1=round(~(~abs(sign(round(diff([con(1),con(3)])))))*...&lt;br&gt;
&amp;gt; 	-2*(~(~(sum(ismember(diff(con),1)))))+1);&lt;br&gt;
&lt;br&gt;
A little description will help us to help you. What does con represent, what are typical values it contains, what size is it? What values do you expect sign1 and sign2 to have?&lt;br&gt;
Darren</description>
    </item>
    <item>
      <pubDate>Mon, 09 Mar 2009 05:38:02 -0400</pubDate>
      <title>Re: How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#633414</link>
      <author>Darren Rowland</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gp295g$dn1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; I created an algorithm and everything works fine, but there are line that I think can be made shorter using a command or technique I don't know about. Here are the lines:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign2=round(((~abs(sign(round(diff([con(1),con(3)])))))*(-2*((~(~(con(3)-con(2)+1)))*...&lt;br&gt;
&amp;gt; (~(~(con(3)-con(2)-2))))+1))+~(~abs(sign(round(diff([con(1),con(3)]))))));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign1=round(~(~abs(sign(round(diff([con(1),con(3)])))))*...&lt;br&gt;
&amp;gt; 	-2*(~(~(sum(ismember(diff(con),1)))))+1);&lt;br&gt;
&lt;br&gt;
A little description will help us to help you. What does con represent, what are typical values it contains, what size is it? What values do you expect sign1 and sign2 to have?&lt;br&gt;
Darren</description>
    </item>
    <item>
      <pubDate>Mon, 09 Mar 2009 06:09:04 -0400</pubDate>
      <title>Re: How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#633417</link>
      <author>Darren Rowland</author>
      <description>My apologies for multiple posts. I'm getting load errors for every page.&lt;br&gt;
&lt;br&gt;
Try the following&lt;br&gt;
~abs(sign(round(diff([con(1),con(3)])))) the same as isequal(con(1),con(3))&lt;br&gt;
and&lt;br&gt;
~(~(sum(ismember(diff(con),1)))) the same as any(diff(con)==1)&lt;br&gt;
Hth&lt;br&gt;
Darren</description>
    </item>
    <item>
      <pubDate>Mon, 09 Mar 2009 06:32:02 -0400</pubDate>
      <title>Re: How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#633418</link>
      <author>Husam Aldahiyat</author>
      <description>&quot;Darren Rowland&quot; &amp;lt;darrenjremovethisrowland@hotmail.com&amp;gt; wrote in message &amp;lt;gp2bq0$500$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; My apologies for multiple posts. I'm getting load errors for every page.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Try the following&lt;br&gt;
&amp;gt; ~abs(sign(round(diff([con(1),con(3)])))) the same as isequal(con(1),con(3))&lt;br&gt;
&amp;gt; and&lt;br&gt;
&amp;gt; ~(~(sum(ismember(diff(con),1)))) the same as any(diff(con)==1)&lt;br&gt;
&amp;gt; Hth&lt;br&gt;
&amp;gt; Darren&lt;br&gt;
&lt;br&gt;
Thanks! &lt;br&gt;
The first was really a test to see if they were equal but I missed the function isequal. &lt;br&gt;
&lt;br&gt;
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). &lt;br&gt;
&lt;br&gt;
Thanks for the help.</description>
    </item>
    <item>
      <pubDate>Mon, 09 Mar 2009 16:47:38 -0400</pubDate>
      <title>Re: How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#633529</link>
      <author>Peter Boettcher</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; &quot;Darren Rowland&quot; &amp;lt;darrenjremovethisrowland@hotmail.com&amp;gt; wrote in message &amp;lt;gp2bq0$500$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; My apologies for multiple posts. I'm getting load errors for every page.&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Try the following&lt;br&gt;
&amp;gt;&amp;gt; ~abs(sign(round(diff([con(1),con(3)])))) the same as isequal(con(1),con(3))&lt;br&gt;
&amp;gt;&amp;gt; and&lt;br&gt;
&amp;gt;&amp;gt; ~(~(sum(ismember(diff(con),1)))) the same as any(diff(con)==1)&lt;br&gt;
&amp;gt;&amp;gt; Hth&lt;br&gt;
&amp;gt;&amp;gt; Darren&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks! &lt;br&gt;
&amp;gt; The first was really a test to see if they were equal but I missed the function isequal. &lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The second was a test if the diff was 1. Also present in the algorithm&lt;br&gt;
&amp;gt; is another test if diff was 2 so I'll use any(diff(con)==2).&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks for the help.&lt;br&gt;
&lt;br&gt;
Other general advice:&lt;br&gt;
&lt;br&gt;
Since these are scalars, == is even better than isequal.  Your first&lt;br&gt;
expression is simply&lt;br&gt;
&lt;br&gt;
con(1)==con(3)&lt;br&gt;
&lt;br&gt;
And if you need to negate it, use con(1)~=con(3)&lt;br&gt;
&lt;br&gt;
I think you'll find that the ~(~(con(3)-con(2)-2)) expressions are also&lt;br&gt;
better written using equalities: con(3)~=con(2)+2&lt;br&gt;
&lt;br&gt;
round does nothing when all the inputs are integers.&lt;br&gt;
&lt;br&gt;
After you've gone through and done all these simplifications, post back&lt;br&gt;
again.  Other stuff might be clearer at that point.&lt;br&gt;
&lt;br&gt;
Depending on what all this means, you might actually think about&lt;br&gt;
specifying the whole thing as a look-up table.  Right now the code means&lt;br&gt;
nothing to me, so a look-up table makes just as much sense:&lt;br&gt;
&lt;br&gt;
sign2(1,1,1) = 1;&lt;br&gt;
sign2(1,1,2) = -1;&lt;br&gt;
&lt;br&gt;
Etc.&lt;br&gt;
&lt;br&gt;
Then just look up your answer with sign2(con(1),con(2),con(3))&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
-Peter</description>
    </item>
    <item>
      <pubDate>Thu, 09 Apr 2009 16:13:01 -0400</pubDate>
      <title>Re: How can I make these lines shorter?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/246190#641686</link>
      <author>Husam Aldahiyat</author>
      <description>Peter Boettcher &amp;lt;boettcher@ll.mit.edu&amp;gt; wrote in message &amp;lt;muyd4cqlk2d.fsf@G99-Boettcher.llan.ll.mit.edu&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &quot;Darren Rowland&quot; &amp;lt;darrenjremovethisrowland@hotmail.com&amp;gt; wrote in message &amp;lt;gp2bq0$500$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; My apologies for multiple posts. I'm getting load errors for every page.&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Try the following&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; ~abs(sign(round(diff([con(1),con(3)])))) the same as isequal(con(1),con(3))&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; and&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; ~(~(sum(ismember(diff(con),1)))) the same as any(diff(con)==1)&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Hth&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Darren&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Thanks! &lt;br&gt;
&amp;gt; &amp;gt; The first was really a test to see if they were equal but I missed the function isequal. &lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; The second was a test if the diff was 1. Also present in the algorithm&lt;br&gt;
&amp;gt; &amp;gt; is another test if diff was 2 so I'll use any(diff(con)==2).&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Thanks for the help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Other general advice:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Since these are scalars, == is even better than isequal.  Your first&lt;br&gt;
&amp;gt; expression is simply&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; con(1)==con(3)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And if you need to negate it, use con(1)~=con(3)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I think you'll find that the ~(~(con(3)-con(2)-2)) expressions are also&lt;br&gt;
&amp;gt; better written using equalities: con(3)~=con(2)+2&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; round does nothing when all the inputs are integers.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; After you've gone through and done all these simplifications, post back&lt;br&gt;
&amp;gt; again.  Other stuff might be clearer at that point.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Depending on what all this means, you might actually think about&lt;br&gt;
&amp;gt; specifying the whole thing as a look-up table.  Right now the code means&lt;br&gt;
&amp;gt; nothing to me, so a look-up table makes just as much sense:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sign2(1,1,1) = 1;&lt;br&gt;
&amp;gt; sign2(1,1,2) = -1;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Etc.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Then just look up your answer with sign2(con(1),con(2),con(3))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Peter&lt;br&gt;
&lt;br&gt;
I can make it a lookup table (only 12 cases for con), but I want to show-off with a short code :S&lt;br&gt;
&lt;br&gt;
Anyway here it is. It takes a rotation matrix R, and an Euler angle convention, then outputs the three angles. It doesn't take care of singularities.&lt;br&gt;
&lt;br&gt;
function s=eul(T,str)&lt;br&gt;
% EUL obtain Euler Angles from R Matrix&lt;br&gt;
% &lt;br&gt;
% Example: &lt;br&gt;
% &amp;gt;&amp;gt;T = [-0.30619     -0.91856         0.25;&lt;br&gt;
%        0.88388     -0.17678      0.43301;&lt;br&gt;
%       -0.35355      0.35355      0.86603];&lt;br&gt;
% &lt;br&gt;
% &amp;gt;&amp;gt;s=eul(T,'zyz') &lt;br&gt;
% s =  &lt;br&gt;
%     g: 0.7854&lt;br&gt;
%     a: 1.0472&lt;br&gt;
%     b: 0.5236&lt;br&gt;
% &lt;br&gt;
% Example:&lt;br&gt;
% &amp;gt;&amp;gt;a = 0.5;&lt;br&gt;
% &amp;gt;&amp;gt;b = 0.7;&lt;br&gt;
% &amp;gt;&amp;gt;g = pi/3;&lt;br&gt;
%&lt;br&gt;
% &amp;gt;&amp;gt;T = rotx(a)*roty(b)*rotz(g);&lt;br&gt;
%&lt;br&gt;
% &amp;gt;&amp;gt;s=eul(T,'xyz')&lt;br&gt;
% s =  &lt;br&gt;
%     g: 1.0472&lt;br&gt;
%     a: 0.5&lt;br&gt;
%     b: 0.7&lt;br&gt;
% &lt;br&gt;
% See also TRANS&lt;br&gt;
% &lt;br&gt;
&lt;br&gt;
s=struct;&lt;br&gt;
&lt;br&gt;
% convert from xyz to 123&lt;br&gt;
con=double(str)-119;&lt;br&gt;
&lt;br&gt;
% get gamma&lt;br&gt;
sign2=round(((con(1)==con(3))*(-2*((~(~(con(3)-con(2)+1)))*...&lt;br&gt;
	(~(~(con(3)-con(2)-2))))+1))+~(con(1)==con(3)));&lt;br&gt;
&lt;br&gt;
sign1=round(~(isequal(con(1),con(3)))*-2*(any(diff(con)==1))+1);&lt;br&gt;
&lt;br&gt;
s.g=atan2(sign1*T(con(1),con(2)),sign2*T(con(1),6-sum([con(3),con(2)])));&lt;br&gt;
&lt;br&gt;
% get alpha&lt;br&gt;
sign2=sign2-(~(con(3)-con(1)))*2*sign2;&lt;br&gt;
&lt;br&gt;
s.a=atan2(sign1*T(con(2),con(3)),sign2*T(6-sum([con(1),con(2)]),con(3)));&lt;br&gt;
&lt;br&gt;
% get beta&lt;br&gt;
T1=eval(['T/rot',str(3),'(',num2str(s.g),')']);&lt;br&gt;
&lt;br&gt;
sign1=~(con(2)-1)*2-1;&lt;br&gt;
&lt;br&gt;
s.b=atan2(sign1*T1((~(con(2)-3)-1)*-2+1,1-(~(con(2)-2)-1)),...&lt;br&gt;
	T1((~(con(2)-3)-1)*-2+1,(~(con(2)-3)-1)*-2+1));&lt;br&gt;
&lt;br&gt;
end</description>
    </item>
  </channel>
</rss>

