Split a larger matrix into smaller matrices

Hello All,
I have a [256 x 5 x 2000] matrix. I want to split this matrix into 5 [256 x 1 x 2000] matrices. Tried using mat2cell but it returns an error stating number of dimensions must match.
Could anyone please help me with this?
Thanks, \Kashif

 採用された回答

Star Strider
Star Strider 2016 年 3 月 17 日

1 投票

The dimensions have to add to the same values in each dimension with mat2cell.
This works:
M = randi(9, 256, 5, 2000); % Create Matrix
C = mat2cell(M, 256, ones(1,5), 2000); % Split To Cells

6 件のコメント

Kash022
Kash022 2016 年 3 月 17 日
Thanks. so now how do I access the individual matrices because C is now 1x5 cell?
Andrei Bobrov
Andrei Bobrov 2016 年 3 月 17 日
C{1} - first matrice, C{2} - second and so on
Kash022
Kash022 2016 年 3 月 17 日
編集済み: Stephen23 2016 年 3 月 17 日
Yes, I am trying this command and its returning me "error using plot, invalid first data argument"
plot(squeeze(K{1}(1,1,:)),'r');
Star Strider
Star Strider 2016 年 3 月 17 日
I’m not certain what you want to plot.
See if this does what you want:
plot(squeeze(C{1}))
Kash022
Kash022 2016 年 3 月 17 日
@Star Strider: Yeps this works...even if I do plot(squeeze(C{1}(1,1,:))); Thanks!
Star Strider
Star Strider 2016 年 3 月 17 日
My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2016 年 3 月 17 日

2 投票

C = num2cell(M,[1 3]);

5 件のコメント

Kash022
Kash022 2016 年 3 月 17 日
Thanks but while doing plot(squeeze(K(1,1,:))); gives me an error.
Andrei Bobrov
Andrei Bobrov 2016 年 3 月 17 日
What is K? It is C?
Kash022
Kash022 2016 年 3 月 17 日
編集済み: Stephen23 2016 年 3 月 17 日
C = mat2cell(My_matrix, 256, ones(1,5), 2000);
K = num2cell(C,[1 5]);
Stephen23
Stephen23 2016 年 3 月 17 日
編集済み: Stephen23 2016 年 3 月 17 日
@ksnf3000: why are you using both num2cell and mat2cell? None of the answers do this. mat2cell splits up your array into pieces and returns a cell array... why do you want to split this up as well? You only need one of them.
Kash022
Kash022 2016 年 3 月 17 日
@Stephen Cobeldick: Yes , your right...can use any one. Thanks once again!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2016 年 3 月 17 日

コメント済み:

2016 年 3 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by