Azzera filtri
Azzera filtri

How to divide matrix with dimension 300x564 to many submatrices

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Walter Roberson
Walter Roberson il 19 Set 2015
B=reshape(A,n/h,h,[]);
  1 Commento
nadia nadi
nadia nadi il 19 Set 2015
Modificato: nadia nadi il 21 Set 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

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by