Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
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
Solved! Go to Solution.
Here is a utility function which splits a Matrix into n smaller ones
and here is the same again with the difference, that the second argument is the maximum number of elements per smaller matrix.
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
No error checking implemented (n larger than number of rows in M, negative or floating point arguments, ...)
Here is a utility function which splits a Matrix into n smaller ones
and here is the same again with the difference, that the second argument is the maximum number of elements per smaller matrix.
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
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.
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.