## Shuffle matrix cells – any ideas?

Jan 2, 2014 at 5:30am

# Shuffle matrix cells – any ideas?

Happy New Year

I’m trying to work out how I can shuffle the cells in a 2-dimensional matrix of arbitrary size: essentially, the effect I want to achieve is much like a jit.repos with a noise input, but I need to be sure that every individual cell in the input matrix is present in the output matrix, just in a different location.

I’m sure that such a thing should be possible, perhaps by iteratively selecting pairs of cells from a list and swapping their positions via jit.repos, but this seems awkward and slow. Any hints from people who have achieved such a thing in the past would be greatly appreciated.

Thanks

Tom

#277151
Jan 2, 2014 at 8:45am

Try using urn to generate your repos coordinates. If your input matrix is larger than 256 elements (the list length limit) you can use multiple urn objects and concatenate the results with an appropriate offset.

Basic technique in the below patcher.

<code>

– Pasted Max Patch, click to expand. –

</code>

#277167
Jan 7, 2014 at 1:33am

Thanks Jesse,

That’s a very elegant solution. I’m still hunting for something that will allow me to do this with much larger matrices though – with dims of at least 200 x 200. Perhaps this is only something achievable with a custom external, which is beyond my capabilities.

Tom

#277617
Jan 7, 2014 at 3:33am

this will allow up to 256 * 256 using 2 urns: one for the x dim and one for the y, so each cell is guaranteed to be uniquely mapped. this example is 50*50, but it doesn’t have to be square

<code>

– Pasted Max Patch, click to expand. –

</code>

#277629
Jan 7, 2014 at 3:48am

Thanks Floating Point, I’d begun to go down this route just now but you got there before me.

This will work perfectly for my current application, and I’ll continue to think about how to do this on an arbitrary sized matrix in the meantime.

Cheers

Tom

#277630
Jan 8, 2014 at 7:43am

Hello all

Just in case it’s useful to anybody else, I’ve tinkered with the patches and added an additional level of scrambling to generate a more seemingly ‘random’ shuffling of cells. This patch still has a matrix dimension limit of 256×256.

Thanks again for the input

Tom

– Pasted Max Patch, click to expand. –
#277737

You must be logged in to reply to this topic.