Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Jan 03, 2022
03:08 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

Jan 03, 2022
03:08 AM

group items and sort table

Hi to all.

I have tables with many elements which I must group according to type and sort them in ascending order based on column 2 of the table in the example file. I have tried to generate a small code but I do not get the desired result.

I hope you can help me.

I attach the file in mathcad Prime with an example of what I want to get.

In advance thank you very much for the help.

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

Jan 03, 2022
09:19 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

Jan 03, 2022
09:19 AM

Here's a function that will do the job:

The first parameter is the matrix you want to sort, the second parameter is the list of columns you successively want to sort on.

Example. Create a matrix with random numbers:

Sort it on columns 1, 3 and then 7:

Or sort it on column7, then 1, then 3:

Note that the function will work with matrix elements being strings or scalars only.

The same function in Prime (but with ORIGIN=0):

Prime 4 file attached.

Success!

Luc

5 REPLIES 5

Jan 03, 2022
04:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

Jan 03, 2022
04:39 AM

You have set ORIGIN=1, so matrix indexes start at 1 (not the default 0). I suppose your 'column 2' of the table is the one labelled 'Col 1' , so its index is 2.

Have you tried

csort(Table1,2)

To sort the entire table on the second column?

I see that you want the table sorted on column 1, and next on column 2.

Now the problem is that while csort does a good job of sorting on one column, if you subsequently sort the resulting sorted table on another column, the first sorting is lost.

The quickest solution to do the sorting of the table you want, is to do it in Excel.

Success!

Luc

Jan 03, 2022
05:05 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

Jan 03, 2022
08:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

Jan 03, 2022
08:46 AM

Just an observation:

EXCEL (in the embedded table) could do this sorting by tipe, then by column 1, in one single operation. No code required.

Jan 03, 2022
09:19 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

Jan 03, 2022
09:19 AM

Here's a function that will do the job:

The first parameter is the matrix you want to sort, the second parameter is the list of columns you successively want to sort on.

Example. Create a matrix with random numbers:

Sort it on columns 1, 3 and then 7:

Or sort it on column7, then 1, then 3:

Note that the function will work with matrix elements being strings or scalars only.

The same function in Prime (but with ORIGIN=0):

Prime 4 file attached.

Success!

Luc

Jan 04, 2022
12:05 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

Jan 04, 2022
12:05 PM

Thanks to all for the help