Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: RE: Sorting rows in Mata


From   Simone Angioloni <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: RE: RE: Sorting rows in Mata
Date   Mon, 24 Feb 2014 21:05:45 +0000

Hi Nick,

I would like to say that I spent some time with the sort() function and a simple while loop and it works.

Thanks.

Simone


________________________________________
From: [email protected] <[email protected]> on behalf of Nick Cox <[email protected]>
Sent: Monday, February 24, 2014 1:09 PM
To: [email protected]
Subject: Re: st: RE: RE: Sorting rows in Mata

You're correct; this is not what you want. Sorry about that.
Nick
[email protected]


On 24 February 2014 18:05, Simone Angioloni <[email protected]> wrote:
> Hi Nick,
>
> I did it, but it does not work.
>
> mymat=(0,3,2,4\3,0,1,6\2,1,0,5\4,6,5,0)
> sort(mymat', 1)'
>
> And this is the output:
>          1   2   3   4
>     +-----------------+
>   1 |  0   2   3   4  |
>   2 |  3   1   0   6  |
>   3 |  2   0   1   5  |
>   4 |  4   5   6   0  |
>     +-----------------+
>
> I do not need to sort only the first row, but all the rows like this:
>          1   2   3   4
>     +-----------------+
>   1 |  0   2   3   4  |
>   2 |  0   1   3   6  |
>   3 |  0   1   2   5  |
>   4 | 0    4   5   6  |
>     +-----------------+
>
> Thanks.
>
> Simone
> ________________________________________
> From: [email protected] <[email protected]> on behalf of Nick Cox <[email protected]>
> Sent: Monday, February 24, 2014 12:54 PM
> To: [email protected]
> Subject: Re: st: RE: RE: Sorting rows in Mata
>
> The -sort()- function (not command) can do this for you, with
> transposes before and after:
>
> : sort(mymat', 1)'
>
> Nick
> [email protected]
>
> Simone Angioloni
>
>> I knew this command, but it seems not perfectly fit.
>>
>> My matrix is like this:
>>
>> mymat=(0,3,2,4\3,0,1,6\2,1,0,5\4,6,5,0)
>>
>> and I need something like:
>>
>> 0,2,3,4
>> 0,1,3,6
>> 0,1,2,5
>> 0,4,5,6
>
> Andrew Maurer
>
>> Is mata's sort() function what you're looking for? Try "help mata sort()"
>>
>> Eg:
>> mata
>> mymat = (3 \ 1 \ 4 \ 2), (6 \ 7 \ 8 \ 9)
>> mymat
>> sort(mymat,1)
>> end
>
> Simone Angioloni
>
>> Is there a canned command to sort rows in ascending order in Mata without exporting the matrix to Stata and using the rowsort()?
>>
>> I need to do that in Mata because the marix is very large (more than 1000 by 1000) and once I export the matrix to Stata I have rounding errors that make the matrix slightly different from the original.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index