<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aptech &#187; Answers for "Sorting all columns in a matrix and sortmc"</title>
	<atom:link href="http://www.aptech.com/questions/sortmc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aptech.com</link>
	<description></description>
	<lastBuildDate>Fri, 08 Feb 2013 19:12:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>By: aptech</title>
		<link>http://www.aptech.com/questions/sortmc/#answer-2006</link>
		<comments>http://www.aptech.com/questions/sortmc/#answer-2006#comments</comments>
		<pubDate>Sun, 14 Oct 2012 19:05:51 +0000</pubDate>
		<dc:creator>aptech</dc:creator>
		
		<guid isPermaLink="false">http://www.aptech.com/questions/sortmc/#answer-2006</guid>
		<description><![CDATA[The best way to sort an entire matrix is probably with a loop. You can make a procedure to hide the details to make your code cleaner, like this: proc (1) = sortallc(x); for i(1, cols(x), 1); x[.,i] = sortc(x[.,i], &#8230; <a href="http://www.aptech.com/questions/sortmc/#answer-2006">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The best way to sort an entire matrix is probably with a loop. You can make a procedure to hide the details to make your code cleaner, like this:</p>
<pre>
proc (1) = sortallc(x);
   for i(1, cols(x), 1);
      x[.,i] = sortc(x[.,i], 1);
   endfor;
   retp(x);
endp;
</pre>
<p>Then in your code, you would just need to say:</p>
<pre>
newx = sortallc(x);
</pre>
<p>The sortmc command keeps all rows together. Since in many cases, rows are observations this is what is most commonly needed. What it does differently is that it will sort later columns based upon tie breakers in the first specified search column. So, the code:</p>
<pre>
x = { 9 2 5 6,
      3 6 1 9,
      3 7 4 1,
      1 2 8 9 };
	 
s1 = sortc(x,1);

s2 = sortmc(x, 1|2);
</pre>
<p>will set &#8216;s1&#8242; and &#8216;s2&#8242; equal to:</p>
<pre>
     1      2      8      9 
s1 = 3      7      4      1 
     3      6      1      9 
     9      2      5      6 

     1      2      8      9 
s2 = 3      6      1      9 
     3      7      4      1 
     9      2      5      6 
</pre>
<p>Notice that rows 2 and 3 have been swapped in &#8216;s2&#8242; because the matrix was sorted based upon row 2 for the rows that matched in column 1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aptech.com/questions/sortmc/#answer-2006/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.aptech.com @ 2013-02-09 01:54:15 --