Using Mathcad Prime for Matrix Row Substitution Based on Matching Criteria
- July 3, 2023
- 3 replies
- 3849 views
Hello Everyone,
I am attempting to write a 'RowSwapper' function in Prime 8. Essentially, I have a matrix 'A' in which I need to replace certain rows that are present in another matrix, 'B'. The function should take the following arguments: RowSwapper(A, B, "label"). It should generate a new matrix, called 'A_Swapped', where rows are swapped only in instances where items have the same ID (column 2) and where label="LoadCase4" (column 5).
However, the function I've developed isn't ideal because it relies on matrix 'A' having a well-defined order, and that matrix 'B' maintains the same order per unique ID as they initially appear in Matrix 'A'. Furthermore, it only includes load cases equivalent to "LoadCase4". Additionally, it's time-consuming in terms of computation.

Screen shot of Matrix A and B:


Desired Output

Please note that I don't currently have access to Prime 9. Feel free to send me screenshots of the Prime 9 solution along with the file, which I can open when I eventually install Prime 9.
Here are the known conditions or specifications:
- Both matrix 'A' and 'B' will have the same number of columns.
- Matrix 'A' and 'B' can have any number of rows.
- If Matrix 'B' contains multiple rows with the same ID and the same load case being searched for, then it should select the row with the highest value in column 10.
- All IDs in Matrix 'A' will be present in Matrix 'B'.
- The original order of Matrix 'A' should be preserved.
- An attached Excel file contains tabs for the content of matrix 'A' and 'B', as well as a tab with the desired output.



