Sort bocks of sorted data based on interdependencies

Hello everyone-
Long time lurker, but still relatively new to Matlab. I have a very large list of transactions, and I'm trying to sort them to make processing faster, and easier to code.
I have the list sorted as far as I can go with sortrows(), and the lines are not any further distiguishable between them with this sort method. I have found that I can match "Balance Amount" of a line within a block of related transactions by removing the value of the current transaction ("Amount") from the "Balance Amount" and use this to index the list withing related blocks. With this method, I get blocks of sorted data (each "prod" is a block).
Now, I just need to sort the blocks with respect to other blocks. I can tell interdependencies of transactions within the blocks and between the blocks, becuase a (-) transaction in "Amount" will be offset by a (+) transaction in another product. But there isn't always an interdependency between blocks, and I can only compare with unique values (there are somtimes duplicate transactions).
An example is below. I can tell the block with the (47,349.16) value should be before the block with the opposing value. If I perfromed this comparison on a unique value in each block, this would be a fool proof sorting method.
Is there a simply/fast way to do this? I was thinking about bsxfun comparison of Amount column from 1 block to the other but honestly I'm having a bit of writers block on this one, but I bet there is a clever way to do this. Any tips appreciated. Thanks !

Answers (0)

Categories

Products

Asked:

on 9 Aug 2022

Edited:

on 9 Aug 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!