cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Sorting a result Matrix

NM_10165576
13-Aquamarine

Sorting a result Matrix

I am sorting a result matrix with respect to 5th column.
If A is more than Asreq, i want to get only positive values of 5th column in a sorted way as an output.
If A is less than Asreq, the output matrix should contain only negative values in 5th column and they should be sorted in reverse order. 
Is this possible in Mathcad?

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:NM_10165576)

The function UpSort(e,5) should do what you want.

See attached worksheet. You may have to force recalculation.

 

Success!
Luc

View solution in original post

9 REPLIES 9
Werner_E
25-Diamond I
(To:NM_10165576)

First of all you always should tstae which version of Prime you are using, especially if you don't use the latest (P10 at this time). I guess you are using Prime 9.

 

Then its unclear to me what exactly you are trying to get.

 

Your program calculates a 66x6 matrix "Res".

Then you eliminate the first (all zeros) row of it.

 

And then you compare A.sreq with A (and you are missing the case when they are equal), But A is just the last value of the fifth column (column with index 4) in the 65th row, which happens to be 7.917 cm^2.

Because A.sreq is larger, the whole matrix is reverse sorted by the last columns values and then you return a subset of this matrix, consisting of no more than 31 rows !?

Thats what you have programmed and thats what you get.

 

Is it really intended to compare A.sreq just with the last calculated A value?

And what is your intended output if its not the 31x6 matrix you now get?

I am not sure what you mean by "If A is less than Asreq, the output matrix should contain only negative values in 5th column and they should be sorted in reverse order. ".

Does it mean that you expect the result you have now but without the first eight rows?

And how many rows? Still limited to 31?

 

Would this modification come near to what you are looking for:

Werner_E_1-1721072138901.png

 

Prime 9 sheet attached

 

 

 

NM_10165576
13-Aquamarine
(To:Werner_E)

The program compare A with Aserf in each iteration and stores in Res.
I just want to sort Res matrix based on 5th column.
5th column contains gqo values. if gqo is more than or equal to zero , the positive values of 5th column should be sorted in ascending order.
if gqo is less than zero , 5th column of matrix contains negative values, which should be sorted in descending order.
for example,

NM_10165576_0-1721110490424.png

And positive values of column 5 should always come first.

Hi,

my suggestion:

  • split the matrix into two
    • 1st matrix ... positive values in 5th column
    • 2nd matrix ... negative values in 5th column
  • sort 1st matrix
  • sort 2nd matrix
  • join 1st + 2nd matrix

 


Martin Hanák

Hi
I understood that i have to do it this way.
But i don't know how to do it in Mathcad programming.

This works. Thank you very much.

LucMeekes
23-Emerald III
(To:NM_10165576)

The function UpSort(e,5) should do what you want.

See attached worksheet. You may have to force recalculation.

 

Success!
Luc

Werner_E
25-Diamond I
(To:NM_10165576)

So this approach should do the job

Werner_E_0-1721136066104.png

It will fail if column #5 of "Res" does not contain any negative values.

If this may be a problem, you can deal with it by using a "try and catch" statement:

Werner_E_1-1721136336392.png

 

Prime 9 sheet attached

Werner_E
25-Diamond I
(To:Werner_E)

The last approach would still fail if all values in column #5 are negative.

This modification deals with that case as well:

Werner_E_0-1721136875870.png

 

NM_10165576
13-Aquamarine
(To:Werner_E)

Thanks a lot.

Announcements

Top Tags