Regarding sorting each row of a matrix seperately

Hello Is there a way to sort each row of a matrix?
If,

a = { 1 2 7 4, 
      1 5 3 8 };

is a matrix with 2 rows and 4 columns, I want to get a matrix that is sorted on its each row separately i.e. I want to get the matrix

b = { 1 2 4 7, 
      1 3 5 8};

Is there any built in function to do that?

Thanks
Annesha

1 Answer



0



There is not built-in function to do that, but you could do this:

a = { 1 2 7 4, 
      1 5 3 8 };
b = sortAllR(a);

proc (1) = sortAllR(a);
   local i;
   for i(1, rows(a), 1);
      a[i,.] = sortr(a[i,.], 1);
   endfor;
   retp(a);
endp;

aptech

1,773

Your Answer

1 Answer

0

There is not built-in function to do that, but you could do this:

a = { 1 2 7 4, 
      1 5 3 8 };
b = sortAllR(a);

proc (1) = sortAllR(a);
   local i;
   for i(1, rows(a), 1);
      a[i,.] = sortr(a[i,.], 1);
   endfor;
   retp(a);
endp;

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy