<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240358</link>
    <title>MATLAB Central Newsreader - sorting algorithm</title>
    <description>Feed for thread: sorting algorithm</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>Wed, 03 Dec 2008 15:48:02 -0500</pubDate>
      <title>sorting algorithm</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240358#614776</link>
      <author>Evren </author>
      <description>Hi I am in a matlab course and the teacher wants us to create a function in MATLAB 7.5.0(R2007b) that does the following &lt;br&gt;
A. Using the input command, you enter a set of number to be sorted as a row vector. the length of the vector is arbitrary. &lt;br&gt;
B. You program should then sort the numbers from the most negative to the most positive. &lt;br&gt;
C. You program should then print out the unsorted list and the sorted list. &lt;br&gt;
D. You can't use the built in matlab sort function to complete this assignmen. You must develop your own sorting algorithm. &lt;br&gt;
&lt;br&gt;
I tried for hours and just can't seem to get it and its do tomorrow. If anyone can help, thank you very much. &lt;br&gt;
&lt;br&gt;
Here is what I got so far with some help, but it still doesn't work.&lt;br&gt;
&lt;br&gt;
for i=1:(n-1)  % n is the length of the vector V &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if V(i)&amp;gt;V(i+1) &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;s = V(i); V(i) = V(i+1); V(i+1) = s; &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end &lt;br&gt;
end</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 15:58:01 -0500</pubDate>
      <title>Re: sorting algorithm</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240358#614780</link>
      <author>Steve Amphlett</author>
      <description>&quot;Evren &quot; &amp;lt;evrenbrs@gmail.com&amp;gt; wrote in message &amp;lt;gh69ni$6gv$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi I am in a matlab course and the teacher wants us to create a function in MATLAB 7.5.0(R2007b) that does the following &lt;br&gt;
&amp;gt; A. Using the input command, you enter a set of number to be sorted as a row vector. the length of the vector is arbitrary. &lt;br&gt;
&amp;gt; B. You program should then sort the numbers from the most negative to the most positive. &lt;br&gt;
&amp;gt; C. You program should then print out the unsorted list and the sorted list. &lt;br&gt;
&amp;gt; D. You can't use the built in matlab sort function to complete this assignmen. You must develop your own sorting algorithm. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I tried for hours and just can't seem to get it and its do tomorrow. If anyone can help, thank you very much. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Here is what I got so far with some help, but it still doesn't work.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:(n-1)  % n is the length of the vector V &lt;br&gt;
&amp;gt;             if V(i)&amp;gt;V(i+1) &lt;br&gt;
&amp;gt;                     s = V(i); V(i) = V(i+1); V(i+1) = s; &lt;br&gt;
&amp;gt;             end &lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
&quot;develop your own sorting algorithm&quot;.  Why??&lt;br&gt;
&lt;br&gt;
Sure you could research classical sorting methods and then implement one in Matlab, but what's the point?  Are you expected to dream up a wholly new scheme?</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 16:04:01 -0500</pubDate>
      <title>Re: sorting algorithm</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240358#614785</link>
      <author>Evren </author>
      <description>&quot;Steve Amphlett&quot; &amp;lt;Firstname.Lastname@Where-I-Work.com&amp;gt; wrote in message &amp;lt;gh6aa9$g95$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Evren &quot; &amp;lt;evrenbrs@gmail.com&amp;gt; wrote in message &amp;lt;gh69ni$6gv$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi I am in a matlab course and the teacher wants us to create a function in MATLAB 7.5.0(R2007b) that does the following &lt;br&gt;
&amp;gt; &amp;gt; A. Using the input command, you enter a set of number to be sorted as a row vector. the length of the vector is arbitrary. &lt;br&gt;
&amp;gt; &amp;gt; B. You program should then sort the numbers from the most negative to the most positive. &lt;br&gt;
&amp;gt; &amp;gt; C. You program should then print out the unsorted list and the sorted list. &lt;br&gt;
&amp;gt; &amp;gt; D. You can't use the built in matlab sort function to complete this assignmen. You must develop your own sorting algorithm. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I tried for hours and just can't seem to get it and its do tomorrow. If anyone can help, thank you very much. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Here is what I got so far with some help, but it still doesn't work.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:(n-1)  % n is the length of the vector V &lt;br&gt;
&amp;gt; &amp;gt;             if V(i)&amp;gt;V(i+1) &lt;br&gt;
&amp;gt; &amp;gt;                     s = V(i); V(i) = V(i+1); V(i+1) = s; &lt;br&gt;
&amp;gt; &amp;gt;             end &lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;develop your own sorting algorithm&quot;.  Why??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Sure you could research classical sorting methods and then implement one in Matlab, but what's the point?  Are you expected to dream up a wholly new scheme?&lt;br&gt;
&lt;br&gt;
thats what i am expected to do.i must develop my sorting code.can you help me with this.what is the wrong with my code?</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 16:10:19 -0500</pubDate>
      <title>Re: sorting algorithm</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240358#614790</link>
      <author>John D'Errico</author>
      <description>&quot;Evren &quot; &amp;lt;evrenbrs@gmail.com&amp;gt; wrote in message &amp;lt;gh6alh$lvv$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I tried for hours and just can't seem to get it and its do tomorrow. If anyone can help, thank you very much. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Here is what I got so far with some help, but it still doesn't work.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; for i=1:(n-1)  % n is the length of the vector V &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;             if V(i)&amp;gt;V(i+1) &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;                     s = V(i); V(i) = V(i+1); V(i+1) = s; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;             end &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &quot;develop your own sorting algorithm&quot;.  Why??&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Sure you could research classical sorting methods and then implement one in Matlab, but what's the point?  Are you expected to dream up a wholly new scheme?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thats what i am expected to do.i must develop my sorting code.can you help me with this.what is the wrong with my code?&lt;br&gt;
&lt;br&gt;
While this will work for two numbers, what happens when&lt;br&gt;
you have 3 numbers? I.e., what if you use your code to&lt;br&gt;
sort the numbers [3 2 1]? Try it. Are they in order? Why&lt;br&gt;
did it fail? Look (carefully) at what it did.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 16:18:02 -0500</pubDate>
      <title>Re: sorting algorithm</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240358#614792</link>
      <author>Evren </author>
      <description>&quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gh6b1b$s8t$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Evren &quot; &amp;lt;evrenbrs@gmail.com&amp;gt; wrote in message &amp;lt;gh6alh$lvv$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; I tried for hours and just can't seem to get it and its do tomorrow. If anyone can help, thank you very much. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Here is what I got so far with some help, but it still doesn't work.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; for i=1:(n-1)  % n is the length of the vector V &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt;             if V(i)&amp;gt;V(i+1) &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt;                     s = V(i); V(i) = V(i+1); V(i+1) = s; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt;             end &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &quot;develop your own sorting algorithm&quot;.  Why??&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Sure you could research classical sorting methods and then implement one in Matlab, but what's the point?  Are you expected to dream up a wholly new scheme?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; thats what i am expected to do.i must develop my sorting code.can you help me with this.what is the wrong with my code?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; While this will work for two numbers, what happens when&lt;br&gt;
&amp;gt; you have 3 numbers? I.e., what if you use your code to&lt;br&gt;
&amp;gt; sort the numbers [3 2 1]? Try it. Are they in order? Why&lt;br&gt;
&amp;gt; did it fail? Look (carefully) at what it did.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
i am trying to understand why it doesnt work but i cant figuger it out.what is the wrong?what can i do to work the code  for more than 5 numbers. i cant solve what to do..i even couldnt work the code yet...</description>
    </item>
    <item>
      <pubDate>Wed, 03 Dec 2008 16:35:04 -0500</pubDate>
      <title>Re: sorting algorithm</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240358#614799</link>
      <author>John D'Errico</author>
      <description>&quot;Evren &quot; &amp;lt;evrenbrs@gmail.com&amp;gt; wrote in message &amp;lt;gh6bfq$6b6$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gh6b1b$s8t$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Evren &quot; &amp;lt;evrenbrs@gmail.com&amp;gt; wrote in message &amp;lt;gh6alh$lvv$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; I tried for hours and just can't seem to get it and its do tomorrow. If anyone can help, thank you very much. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; Here is what I got so far with some help, but it still doesn't work.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; for i=1:(n-1)  % n is the length of the vector V &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt;             if V(i)&amp;gt;V(i+1) &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt;                     s = V(i); V(i) = V(i+1); V(i+1) = s; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt;             end &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &quot;develop your own sorting algorithm&quot;.  Why??&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; Sure you could research classical sorting methods and then implement one in Matlab, but what's the point?  Are you expected to dream up a wholly new scheme?&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; thats what i am expected to do.i must develop my sorting code.can you help me with this.what is the wrong with my code?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; While this will work for two numbers, what happens when&lt;br&gt;
&amp;gt; &amp;gt; you have 3 numbers? I.e., what if you use your code to&lt;br&gt;
&amp;gt; &amp;gt; sort the numbers [3 2 1]? Try it. Are they in order? Why&lt;br&gt;
&amp;gt; &amp;gt; did it fail? Look (carefully) at what it did.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; John&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; i am trying to understand why it doesnt work but i cant figuger it out.what is the wrong?what can i do to work the code  for more than 5 numbers. i cant solve what to do..i even couldnt work the code yet...&lt;br&gt;
&lt;br&gt;
Ok. Think about what would happen if you applied your&lt;br&gt;
sorting scheme to the numbers a SECOND time. Would&lt;br&gt;
a second pass through your scheme guarantee that three&lt;br&gt;
numbers will always be sorted properly?&lt;br&gt;
&lt;br&gt;
Why does a single loop such as your fails to give a sorted&lt;br&gt;
vector? Apply it to the numbers [3 2 1]. The first test in&lt;br&gt;
your loop will convert this set into [2 3 1]. Then the second&lt;br&gt;
test yields [2 1 3]. These are clearly not sorted, yet you are&lt;br&gt;
closer to that goal. &lt;br&gt;
&lt;br&gt;
Now make a second pass through. What happens? Think&lt;br&gt;
about it. Then try again with the numbers [4 3 2 1]. Can&lt;br&gt;
you sort them using your scheme? Will a second pass&lt;br&gt;
succeed?&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

