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

8 Ansichten (letzte 30 Tage)
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 Kommentar
Moses Tang
Moses Tang am 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...

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 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 Kommentare
Moses Tang
Moses Tang am 28 Feb. 2019
Alright thank you very much.
I will take a good look of it. Thanks for everything. ^^

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Guillaume
Guillaume am 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.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by