For Programmers: Free Programming Magazines  


Home > Archive > Matlab > April 2005 > Re: sorting the numbers considering given precisio









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: sorting the numbers considering given precisio
Jérôme

2005-04-28, 9:00 am

Hi,

What is the difference between :

sort(10^precision*A)

and

sort(A)

Seems that I misunderstood something :(
Jérôme
Steve Amphlett

2005-04-28, 9:00 am

Jérôme wrote:
>
>
> Hi,
>
> What is the difference between :
>
> sort(10^precision*A)
>
> and
>
> sort(A)
>
> Seems that I misunderstood something :(
> Jérôme


Oops, I forgot the <round>. Doh!

precision=3;
[idx,idx]=sort(round(10^precision*A),'de
scend');
A_sort=A(idx)
Jérôme

2005-04-28, 9:00 am

Steve Amphlett wrote:

>
> Oops, I forgot the <round>. Doh!


> precision=3;
> [idx,idx]=sort(round(10^precision*A),'de
scend');
> A_sort=A(idx)


OK Steve, perhaps I need coffee but :

what is the difference between :

sort(round(10^precision*A))

and

sort(A)

I take a coffee...
Jérôme
Steve Amphlett

2005-04-28, 9:00 am

Jérôme wrote:
>
>
> Steve Amphlett wrote:
>
>
>
> OK Steve, perhaps I need coffee but :
>
> what is the difference between :
>
> sort(round(10^precision*A))
>
> and
>
> sort(A)


For the example input given, nothing. But try this:

precision=3;
A=rand(1000,1);
[idx1,idx1]=sort(round(10^precision*A),'
descend');
[idx2,idx2]=sort(A,'descend');
all(idx1==idx2)

ans =

0[color=darkred]

ans =

628
Jérôme

2005-04-28, 9:00 am

After a great black coffee :

I know differences between the two codes you post.
But I think these differences match the "or" in the question :

sortedA = [1.2000;
1.013
1.0123 or 1.0124
1.0124 1.0123
1.0112];

So to me, in that case, both give the same (good) result !

Jérôme
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com