<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Reversal of a sort</title>
	<atom:link href="http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Steve Eddins</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32390</link>
		<dc:creator>Steve Eddins</dc:creator>
		<pubDate>Fri, 22 Jul 2011 11:59:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32390</guid>
		<description>Roy&#8212;Since you&#039;re calling colfilt, you must have Image Processing Toolbox, so I suggest that you call imdilate in order to find local maxima in an image.</description>
		<content:encoded><![CDATA[<p>Roy&mdash;Since you&#8217;re calling colfilt, you must have Image Processing Toolbox, so I suggest that you call imdilate in order to find local maxima in an image.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32389</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 22 Jul 2011 11:12:29 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32389</guid>
		<description>Roy-

Interesting application.  Glad this was useful to you.

--Loren</description>
		<content:encoded><![CDATA[<p>Roy-</p>
<p>Interesting application.  Glad this was useful to you.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roy</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32388</link>
		<dc:creator>Roy</dc:creator>
		<pubDate>Thu, 21 Jul 2011 21:42:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32388</guid>
		<description>Thanks for the entry! it was very useful. I was struggling in how to assign each pixel in a matrix its rank. I guessed it has to do with sort, but the inverse sort was actually what I was after. 

I&#039;m trying to find local maxima in an image. Converting to probabilities (rank/numel) and running a local product (colfilt(img,[3 3],&#039;sliding&#039;,@prod)) worked really great, 

Roy</description>
		<content:encoded><![CDATA[<p>Thanks for the entry! it was very useful. I was struggling in how to assign each pixel in a matrix its rank. I guessed it has to do with sort, but the inverse sort was actually what I was after. </p>
<p>I&#8217;m trying to find local maxima in an image. Converting to probabilities (rank/numel) and running a local product (colfilt(img,[3 3],&#8217;sliding&#8217;,@prod)) worked really great, </p>
<p>Roy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve L</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32378</link>
		<dc:creator>Steve L</dc:creator>
		<pubDate>Mon, 11 Jul 2011 20:34:58 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32378</guid>
		<description>Twilighter,

Use the dimension input argument for SORT to sort the matrix along the rows or down the columns.

&lt;pre&gt;
A = magic(3)
sortDownCols = sort(A, 1)
sortAlongRows = sort(A, 2)
&lt;/pre&gt;

Loren wrote about using the dimension input argument with the SUM function about two months prior to this post:

http://blogs.mathworks.com/loren/2007/06/29/sum-things-to-consider/</description>
		<content:encoded><![CDATA[<p>Twilighter,</p>
<p>Use the dimension input argument for SORT to sort the matrix along the rows or down the columns.</p>
<pre>
A = magic(3)
sortDownCols = sort(A, 1)
sortAlongRows = sort(A, 2)
</pre>
<p>Loren wrote about using the dimension input argument with the SUM function about two months prior to this post:</p>
<p><a href="http://blogs.mathworks.com/loren/2007/06/29/sum-things-to-consider/" rel="nofollow">http://blogs.mathworks.com/loren/2007/06/29/sum-things-to-consider/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Twilighter</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32377</link>
		<dc:creator>Twilighter</dc:creator>
		<pubDate>Mon, 11 Jul 2011 12:44:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32377</guid>
		<description>when i need to sort a matrix here what i do

[m,n] = size(X);
newX = reshape(X,1,m*n);

then use the same thing as loren did with A &amp; B vector

then again reshape my sorted vector back to matrix

this way of sorting is equal to sorting by column then sorting the rows

but if u need to sort only the columns or rows of matrix i dunno how to do it</description>
		<content:encoded><![CDATA[<p>when i need to sort a matrix here what i do</p>
<p>[m,n] = size(X);<br />
newX = reshape(X,1,m*n);</p>
<p>then use the same thing as loren did with A &amp; B vector</p>
<p>then again reshape my sorted vector back to matrix</p>
<p>this way of sorting is equal to sorting by column then sorting the rows</p>
<p>but if u need to sort only the columns or rows of matrix i dunno how to do it</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32286</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 24 May 2011 11:18:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32286</guid>
		<description>Mike B-

There is an example in the help to show how to undo the sort.  You need to save the indices from the initial sort and use those with the new data.

--Loren</description>
		<content:encoded><![CDATA[<p>Mike B-</p>
<p>There is an example in the help to show how to undo the sort.  You need to save the indices from the initial sort and use those with the new data.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike B</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32285</link>
		<dc:creator>Mike B</dc:creator>
		<pubDate>Tue, 24 May 2011 06:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32285</guid>
		<description>Can reverse sort work with a matrix where each column has been sorted?

I am trying to do the following:

let&#039;s say i have a matrix &#039;A&#039; of 7000 rows by 50 columns, and i sort using the following:
&lt;pre&gt;
[sortA, ind] = sort(A,&#039;descend&#039;);
&lt;/pre&gt;

now I export this matrix as a .txt file and replace all of the values in Excel with different ones. Then import the altered matrix back into matlab as &#039;B&#039;. Therefore &#039;B&#039; has the same dimensions as A but the values have been altered. How can i apply the reverse sort (&#039;SortA&#039; to &#039;A&#039;) to matrix &#039;B&#039;? 
Thanks in advance.</description>
		<content:encoded><![CDATA[<p>Can reverse sort work with a matrix where each column has been sorted?</p>
<p>I am trying to do the following:</p>
<p>let&#8217;s say i have a matrix &#8216;A&#8217; of 7000 rows by 50 columns, and i sort using the following:</p>
<pre>
[sortA, ind] = sort(A,'descend');
</pre>
<p>now I export this matrix as a .txt file and replace all of the values in Excel with different ones. Then import the altered matrix back into matlab as &#8216;B&#8217;. Therefore &#8216;B&#8217; has the same dimensions as A but the values have been altered. How can i apply the reverse sort (&#8216;SortA&#8217; to &#8216;A&#8217;) to matrix &#8216;B&#8217;?<br />
Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek  O'Connor</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32002</link>
		<dc:creator>Derek  O'Connor</dc:creator>
		<pubDate>Mon, 31 Jan 2011 23:46:34 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-32002</guid>
		<description>Qiang,

Here is one solution:

&lt;pre&gt;
function idx = USearch(p,v);
% 
% Un-Ordered Search for idx : v = p(idx).
% Complexity: O(n);
% USE: for i = 1:7,p(i) = USearch(a,b(i)); end;
% Derek O&#039;Connor, 31 Jan 2011.
%
n = length(p);
idx=0;
for k = 1:n
    if p(k) == v
        idx=k;
        return;             % stops after first find.
    end;
end;
return; % USearch
&lt;/pre&gt;

Use this function as follows:
&lt;pre&gt;
&gt;&gt; for i = 1:7,p(i)=USearch(a,b(i)); end; disp(p)
     5     1     3     6     7     2     4
&lt;/pre&gt;

Unfortunately this method of finding p(1:n) is O(n^2).

Homework Assignment (Due 7 Jan 2011): Find a quicker method.

Good luck,  Derek O&#039;Connor.</description>
		<content:encoded><![CDATA[<p>Qiang,</p>
<p>Here is one solution:</p>
<pre>
function idx = USearch(p,v);
%
% Un-Ordered Search for idx : v = p(idx).
% Complexity: O(n);
% USE: for i = 1:7,p(i) = USearch(a,b(i)); end;
% Derek O'Connor, 31 Jan 2011.
%
n = length(p);
idx=0;
for k = 1:n
    if p(k) == v
        idx=k;
        return;             % stops after first find.
    end;
end;
return; % USearch
</pre>
<p>Use this function as follows:</p>
<pre>
&gt;&gt; for i = 1:7,p(i)=USearch(a,b(i)); end; disp(p)
     5     1     3     6     7     2     4
</pre>
<p>Unfortunately this method of finding p(1:n) is O(n^2).</p>
<p>Homework Assignment (Due 7 Jan 2011): Find a quicker method.</p>
<p>Good luck,  Derek O&#8217;Connor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: an actuary</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-31946</link>
		<dc:creator>an actuary</dc:creator>
		<pubDate>Fri, 07 Jan 2011 12:47:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-31946</guid>
		<description>this is quite often used in actuarial science to induce dependence into a sample which is uncorrelated a priori.

see the document 
Correlation and aggregate loss distributions with an emphasis on the Iman-Conover Method. Mildenhall, S.J. 2005</description>
		<content:encoded><![CDATA[<p>this is quite often used in actuarial science to induce dependence into a sample which is uncorrelated a priori.</p>
<p>see the document<br />
Correlation and aggregate loss distributions with an emphasis on the Iman-Conover Method. Mildenhall, S.J. 2005</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-31896</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 07 Dec 2010 21:06:06 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/08/21/reversal-of-a-sort/#comment-31896</guid>
		<description>Qiang-

Fun question, easy answer if you know what function to use:

&lt;pre class=&quot;code&quot;&gt;
a = [1 8 3 17 0 4 7]
b = [0 1 3 4 7 8 17]
[~,ind] = ismember(b,a)

% the output
&gt;&gt; a = [1 8 3 17 0 4 7]
a =
     1     8     3    17     0     4     7
&gt;&gt; b = [0 1 3 4 7 8 17]
b =
     0     1     3     4     7     8    17
&gt;&gt; [~,ind] = ismember(b,a)
ind =
     5     1     3     6     7     2     4

&lt;/pre&gt;

--Loren</description>
		<content:encoded><![CDATA[<p>Qiang-</p>
<p>Fun question, easy answer if you know what function to use:</p>
<pre class="code">
a = [1 8 3 17 0 4 7]
b = [0 1 3 4 7 8 17]
[~,ind] = ismember(b,a)

% the output
>> a = [1 8 3 17 0 4 7]
a =
     1     8     3    17     0     4     7
>> b = [0 1 3 4 7 8 17]
b =
     0     1     3     4     7     8    17
>> [~,ind] = ismember(b,a)
ind =
     5     1     3     6     7     2     4
</pre>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

