pseudo code (sort)
hello I am trying to sort a matrix in ascending order by column. I know I can just use the sort function but this is a homework assignment and it requires me to do so(being honest). I feel like I am very close to finishing this pseudo code but not quite there. the problem I am having is that I only end up with the last column of the matrix ( sorted ) , what i do know is that each time the "for" statement executes the last column that was sorted gets over written next one. if someone can help me approach this (or solve with explanation) that would be great, but i do prefer a guidance over an exact answer. thanks in advance. (below is a picture of the final result) when i do not suppress "s" i can clearly see that all my columns are being sorted, just stumped on fixing it...
a = randi([0,100],10,5); [r,c] = size(a); temp = 0;
for x = 1:c
s=a(:,x);
for jj=1:r
for ii = 1:jj
if(s(ii)>s(jj))
temp=s(ii);
s(ii)=s(jj);
s(jj)=temp;
end
end
end
end
.png)
3 Comments
Answers (0)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!