How to divide matrix with dimension 300x564 to many submatrices

1 Ansicht (letzte 30 Tage)
nadia nadi
nadia nadi am 19 Sep. 2015
Bearbeitet: nadia nadi am 21 Sep. 2015
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

Antworten (1)

Walter Roberson
Walter Roberson am 19 Sep. 2015
B=reshape(A,n/h,h,[]);
  1 Kommentar
nadia nadi
nadia nadi am 19 Sep. 2015
Bearbeitet: nadia nadi am 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices 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