Matrices, change diagonal elements in nxn matrix from 3nx3 matrix.
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I would like to know how to reshape multidimanrtional matrix into a matrix with diagonal elements.
I have A(n,3,3) matrix that I would like to transform to B(n,m) matrix. Elements for B matrix must be diagonal and are defined as B((j-1)*3+1:j*3, (i-1)*3+1:i*3)=([A(n,1,:) A(n,2,:) A(n,3,:);A(n+1,1,:) A(n+1,2,:) A(n+1,3,:);A(n+2,1,:) A(n+2,2,:) A(n+2,3,:)]), where n is number of rows in A matrix.
B((j-1)*3+1:j*3, (i-1)*3+1:i*3)=squeeze(A(j,:,:)) does not work. It gives me back randomly placed elements from A into B.
An example of what I need is:
A(n,3,:)= [1,2,3;
4,5,6;
7,8,9;
10,11,12;
13,14,15;
16,17,18;.....] transformed into
B(n,m)=[1,2,3,0,0,0,0.....,0;
4,5,6,0,0,0,0.....,0;
7,8,9,0,0,0,0.....,0;
0,0,0,10,11,12;0.....,0;
0,0,0,13,14,15,0......,0;
0,0,0, 16,17,18,0......,0;
........]
Thank you.
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal 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!