Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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?
Solved! Go to Solution.
The function UpSort(e,5) should do what you want.
See attached worksheet. You may have to force recalculation.
Success!
Luc
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:
Prime 9 sheet attached
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,
And positive values of column 5 should always come first.
Hi,
my suggestion:
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.
The function UpSort(e,5) should do what you want.
See attached worksheet. You may have to force recalculation.
Success!
Luc
So this approach should do the job
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:
Prime 9 sheet attached
The last approach would still fail if all values in column #5 are negative.
This modification deals with that case as well:
Thanks a lot.