## resize a matrix non destructively?

Oct 20, 2010 at 11:04am

# resize a matrix non destructively?

Hi,

I have a multiplane matrix which is being filled data one row at a time using jit.fill and an offset command.

I want to resize the matrix on the fly, taking its dimensions from say 1×100 to 1×10.

When i send the matrix a “dim 1 \$1″ command the matrix is resized correctly but all the data is deleted.

Is there a way to resize the matrix but keep all the data intact? I thought i might be overlooking an easy command?

Otherwise I guess i’ll have to keep a 2nd copy of the matrix, resize the 1st matrix then refill it with the data from the second matrix? How does this sound?

Look forward to hearing some opinions,

Will

#52843
Oct 20, 2010 at 1:27pm

will jit.submatrix help?

#189953
Oct 20, 2010 at 3:45pm

just connect two jit.matrix objects as below:

[jit.matrix 1 100]
|
[jit.matrix 1 10]

#189954
Oct 20, 2010 at 11:05pm

Thanks for the input, I’ve spent the day looking into these and other various ways forward but have had no luck,

I guess I should have been more clear about what im aiming for,

I have a multiplane matrix 6 planes each 1 by 1024 filled with values which i want to keep intact.

1- Using [number box] id like to reduce the matrix down to “1 by [number box]” keeping the values that exist in this range unchanged.

2- Id then like to be able to increase the matrix to “1 by [number box}” any new cells made should be filled with 0′s.

So far i’ve found a convoluted way of almost achieving 1, although instead of reducing the matrix’s dimensions the values im wanting to get rid of are replaced with zeros- this is not a massive problem.

However when I scale the matrix back up the new values are not replaced with zero’s, they’re going back to what was previously in the matrix.

I’ve attached a patch which demonstrated the problem. opening up p interface and p matrix planes shows what im getting at. using the lcd in ‘p interface’ puts values into the matrix. scrolling the ‘total objects’ number box increases and decreases the matrix. the matrix is viewable in ‘p matrix planes’

If anyone could take a look at the patch id really appreciate it, thought id be able to sort it out in a couple of hours but have been at it all day with no luck so far!

###### Attachments:
1. scaling_matrix.maxpat
#189955
Oct 21, 2010 at 2:03pm

Sorry I don’t have time to study your patch, but maybe this example will be helpful(?). The example uses a 4-plane 256×256 matrix for easy visualization, but it could easily be adapted to a 6-plane 1×1024 matrix.

– Pasted Max Patch, click to expand. –
#189956
Oct 21, 2010 at 3:16pm

Oops. A small misspelling in the above patch: the word “dsdimstart” should be changed to “dstdimstart”.
Corrected version below.

– Pasted Max Patch, click to expand. –
#189957
Oct 22, 2010 at 3:42pm

Hi Christopher,
Thank you! Thats almost exactly what I was looking for, I had tried the dstdimstart stuff but had gotten it all wrong, your example really makes sense of it. Your patch works brilliantly when scaling the matrix down but when I scale it back up id like the freshly viewable values to be reset to zero- im going to have a look at using setcell for those bits.
Thanks again, was going a bit crazy with it!

#189958
Oct 22, 2010 at 7:40pm

I’m glad it was helpful. To set all values in a matrix to 0 most quickly, use the ‘clear’ message. To set them all to something else, use the ‘setall ‘ message. Then, by specifying the dststartdim and dstenddim points, you can impose a smaller matrix onto a part of the larger one, changing all those values while leaving the others as you set them.

#189959
Feb 12, 2013 at 5:34am

hate to dig up old dead threads but I was looking for an answer its one of the best returns on searches for resizing matrices nondestructively, turns out you can use the method posted here and also use a submatrix object, which can then be dynamically resized without information loss

#189960

You must be logged in to reply to this topic.