Is there another way to use mat2cell more efficiently when facing large matrices?

4 views (last 30 days)
My project right now need to handle extreme size matrices. But I need to split them into equal sizes matrices in terms of a cell column for further calculation.
Right now my method of approach:
Assume A1 is the targeted matrix, where A1= 192x8
If I need to split it into each 8x8 matrix, well 192/8 = 24 cells.
My working on this matter:
d = mat2cell(A1U,[N N N N N N N N N N N N N N N N N N N N N N N N],N) %where N = 8
d = 24x1 cell group
{8×8 double}
{8×8 double}
{8×8 double} ..... total of 24
Although right now I can still handle these kind of sizes, but my target was a 1474560 x 64 matrix.
If so then I need to type 1474560 / 64 = 23040 times of N in the equation.
Is there a better way to tackle this problem?
  1 Comment
Moses Tang
Moses Tang on 28 Feb 2019
Or should I choose another way to split it into cell column formats?
Maybe consider each sets of rows using a for loop?
But then need to reform it into a cell column...
Not sure what would be the better approach...

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 28 Feb 2019
Use a ND array instead of cell array:
permute(reshape(A1.',size(A1,2),[],size(A1,1)/N),[2 1 3]) % A - your matrix ,N = 8
  4 Comments
Moses Tang
Moses Tang on 28 Feb 2019
Alright thank you very much.
I will take a good look of it. Thanks for everything. ^^

Sign in to comment.

More Answers (1)

Guillaume
Guillaume on 28 Feb 2019
If so then I need to type 1474560 / 64 = 23040 times of N in the equation.
Of course not! And you never had to type N more than once:
N = 8
numblocks = 64
d = mat2cell(A, repelem(N, numblocks), N)
Note that if you have the image processing toolbox, you could use blockproc to do the splitting and looping for you.
It may also be that you don't need to use a cell array at all (there's a fair bit of memory and speed overhead with cell arrays). Madhan's suggestion of using ND arrays is one way, or just looping over the indices in steps of 8.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!