convert matrix

how can I convert a 6-dimensional matrix into a matrix of dimension 4 then 2

댓글 수: 1

Jan
Jan 2011년 6월 1일
To let us understand what you are looking for, explain: SIZE(Inputs), kind of operation, SIZE(Outputs).

댓글을 달려면 로그인하십시오.

답변 (4개)

Jan
Jan 2011년 6월 1일

1 개 추천

A 6-dimensional array (a "matrix" has 2 dimensions):
X = rand(2,3,4,5,6,7);
It is impossible to reshape this to the dimensions [4 x 2], which would be a matrix. So actual I believe that RESHAPE will do what you want, but a further explanaiotion of the wanted result is needed.
Andrei Bobrov
Andrei Bobrov 2011년 6월 1일

1 개 추천

A = rand(6,1) % array dimension 6x1
out = reshape(A,4,2);

댓글 수: 3

Jan
Jan 2011년 6월 1일
While we all agree, that the OP looks for RESHAPE, "6-dimensional" and "dimension 4 then 2" is questionable. Your interpretation seems to be the smartest yet (+1). It would be so nice if Samia cares about the tread and explains what was actually meant.
samia
samia 2011년 6월 1일
if A is a matrix of size [8 8 3 3 32 32]how to convert to B of dimension 4 ,I dont want to use "RESHAPE"
Jan
Jan 2011년 6월 1일
What is "dimension 4"? Please try to use a proper Matlab terminology. See the commands SIZE and NDIMS.
I do not see any way to face the fact, that you do not "want" to use RESHAPE. Either RESHAPE creates the correct results, or you are looking for something else but did not explain it very well -- in both cases "wanting" does not matter.

댓글을 달려면 로그인하십시오.

Igor
Igor 2011년 6월 1일

0 개 추천

6?? see
reshape()
Laura Proctor
Laura Proctor 2011년 6월 1일

0 개 추천

The results below will reshape from a 6D to a 4D array. If you don't want to use reshape, is there something else you have in mind?
A = rand(8,8,3, 3, 32, 32);
B = reshape(A,[],64,8,6);

댓글 수: 8

samia
samia 2011년 6월 1일
So I simply give the problem:
I have a matrix A of size 256 * 256 I divided into blocks of 8 * 8 blocks are grouped into these 9 (3 * 3 blocks of 8 * 8) I hope that the trick is clear.
First of all I do these steps as follows:
a=3;
N=length(I);
B=[];
i=1;j=1;bi=1;bj=1;
while(i<=N-a+1)
while(j<=N-a+1)
B(:,:,bi,bj)=I(i:i+a-1,j:j+a-1);
j=j+a;
bj=bj+1;
end
i=i+a;
bi=bi+1;
j=1;
bj=1;
end
L=size(B,3);
C=size(B,4);
i=1;j=1;gri=1;grj=1;
while(i<=L-2)
while(j<=C-2)
gr9(:,:,:,:,gri,grj)=B(:,:,i:i+2,j:j+2);
j=j+1;
grj=grj+1;
end
i=i+1;
gri=gri+1;
j=1;
grj=1;
end
now how do the reverse path to return to A
Jan
Jan 2011년 6월 1일
Using FOR loops would increase the readability.
I'm surprised that you can divide a 256x256 matrix to 9 8x8 blocks.
samia
samia 2011년 6월 1일
I put each 9 block of 8*8 together !!!!
Jan
Jan 2011년 6월 1일
@Samia: Sorry, it is not getting clearer. What does "put together" mean? 256*256 is simply not dividable by 9. Is it possible to replace your program by a single line containing RESHAPE and PERMUTE?
Matt Fig
Matt Fig 2011년 6월 1일
I see this is more than a simple reshape. If size(I) = [256 256], then size(gr9) = [3 3 3 3 83 83], so that gr9 has 8.5 times _more_ elements than I! So it is not so simple as breaking a matrix into blocks.
Jan
Jan 2011년 6월 1일
@Matt: Do you understand how [3 3 3 3 83 83] and "put each 9 block of 8*8" match together?
Matt Fig
Matt Fig 2011년 6월 1일
@Jan: No. I simply don't understand the way samia is doing this. The smallest I for which I can get the code to produce a 6D gr9 is:
I = round(rand(12,12)*200);
which produces a gr9 of size [3 3 3 3 2 2]. This I can actually trace through and look at how the elements of gr9 are taken, but I see no clear patter that I think would extend to I 256-by-256... With the latter I of course there is no chance of tracing through!
samia
samia 2011년 6월 1일
I know it is not simple to understand! look: after devide A into block of 8*8 you get for example B; size(B) is [8 8 30 30] with last code now you take B and grouped each 9 small block together (small block mean block of 8*8) you gr9 of size= [8 8 3 3 30 30 ] you can test this result.
my problem is in the reverse path

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2011년 6월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by