How to divide matrix with dimension 300x564 to many submatrices

1 view (last 30 days)
Dear,
I tried to divided a matrix with dimension 300x564 to four or two or even 12 matrices in this code but it give error while for a matrix 500x500 or 100x100 it ok. I change h to the number of sub matrices I want. I have problem with reshape.
[m,n]=size(res);
h=2;
nn=fix(n/(n/h));
m1=n-nn;
res(:,end+1:end+mod(2-m1,2))=nan;
A=res(:,1:end);
B=reshape(A,n,n/h,[]);
[m,n,p]=size(B);
OUT=zeros(m,n,p);
I got this error.
Error using reshape Product of known dimensions, 79524, not divisible into total number of elements, 169200.
Error in SRBM (line 22)
B=reshape(A,n,n/4,[]);
and Error using reshape Product of known dimensions, 159048, not divisible into total number of elements, 169200, if I want to divide for two submatrices.
thanks for any help.
Nadia

Answers (1)

Walter Roberson
Walter Roberson on 19 Sep 2015
B=reshape(A,n/h,h,[]);
  1 Comment
nadia nadi
nadia nadi on 19 Sep 2015
Edited: nadia nadi on 21 Sep 2015
Dear Walter,
I wrote it like this
[m,n]=size(res);
h=4;
nn=fix(n/(n/h));
m1=n-nn;
res(:,end+1:end+mod(2-m1,2))=nan;
A=res(:,1:end);
B=reshape(A,m,n/h,[]);
Now it works.
many thanks,
Nadia

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices 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!