cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Dividing a Matrix into Multiple matrices

KAL_1625
9-Granite

Dividing a Matrix into Multiple matrices

Hi team, I have a column matrix with 98400 rows. I want to divide this matrix into multiple matrices with 25 elements in it each. So 3936 matrices. And want to store all the 3936 matrices in a variable, so that I can call each matrix with indexing. 
For example I have Matrix C with 1 column and 98400 rows. I want to divide C matrix into 3936 matrices, and also able to call each C1, C2..C3936 matrices with 25 elements each.
I am trying to do this using for loop but there has been no success.
In the attached example I have given a column matrix with 50 elements. and want to work out to divide that into 2 matrices.
Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Here is a utility function which splits a Matrix into n smaller ones

Werner_E_0-1665015675330.png

and here is the same again with the difference, that the second argument is the maximum number of elements per smaller matrix.

Werner_E_1-1665015749683.png

To split your matrix with 50 elements into two smaller ones with 25 elements each you would either use split(Column,2) or split2(Column,25).

Here are other examples

Werner_E_2-1665015886170.png

No error checking implemented (n larger than number of rows in M, negative or floating point arguments, ...)

 

 

View solution in original post

4 REPLIES 4

Here is a utility function which splits a Matrix into n smaller ones

Werner_E_0-1665015675330.png

and here is the same again with the difference, that the second argument is the maximum number of elements per smaller matrix.

Werner_E_1-1665015749683.png

To split your matrix with 50 elements into two smaller ones with 25 elements each you would either use split(Column,2) or split2(Column,25).

Here are other examples

Werner_E_2-1665015886170.png

No error checking implemented (n larger than number of rows in M, negative or floating point arguments, ...)

 

 

Thanks for letting me know that there is a function to split a matrix. I was not aware of that. It will be really helpful for me to know in future problems, but I was looking for a different sort of solution. Or maybe I was not clear with what I wanted as a solution.  I was able to work through it and solve the problem using for loop. Here is the screenshot of what the loop looks like. It divides the one column matrix into 2 different matrix with same number of elements.

 

KAL_1625_1-1665020169016.png

 

if you look at the two "split" functions I posted you should see that they are doing exactly what you demand, just, more generic and not limited to just two smaller matrices.

Try sol1:=split(D,2) or sol2:=split2(D,25) and you will see that both sol1  and sol2 are identical to your solution.

Yeah I agree with your solution. It gives the same answer. Also want to add that using the for loop I have used divided by 2 ehich can be relaced by the n number of matrices we want and that would make it generic too. Thanks. 

Top Tags