I wrote the code to sort number in descending order but my code failed to do so (actually i was the failure lol).
Example: Consider, the given array is x=[4 6 9 2 5 0 1] and i want the output y as [9 6 5 4 2 1 0].
What is more, my thinking was like that in seq-
1) Find maximum number from a given array
2) Then use find function to detect the maximum element idexing
3) And then remove the maximum number from the array and reducing the array length
However, i am successfully failed to do what i am looking for. I am determined to use only the while loop to execute this code (nothing else is appreciable e.g sort function and for loop)
Can anyone tell me where i did wrong while i was writing the code? i mean the erroneous part of the code.
I will be glad if any expert give me an advice or suggestion to correct the the code.
function y =sortingnumsindes(x)y=[];while(numel(x)>0) y=max(x); p=find(x==y); x(p)=[]; end y=x;end
Best Answer