Ensamblar varias submatrices en una matriz

조회 수: 8 (최근 30일)
Isabel Aldana Benavides
Isabel Aldana Benavides 2020년 4월 21일
답변: Stephen23 2020년 4월 21일
Hola,
Yo debo en una matriz de ceros de nxn, por ejemplo:
A=[0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0]
Y tengo una submatriz:
M=[1 5 6 1 2 5
7 9 11 3 4 6]
Donde las última 3 columnas de M, corresponde a donde debe ir ubicado el número de las columnas 1,2 y 3 respectivamente, las localizaciones son iguales, es decir para el elemento 7 de la matriz M (fila 2 columna 1, va ir localizada en la matriz de ceros en la fila 3 columna 3):
AA=[1 0 0 0 0 0
0 5 0 0 0 0
0 0 7 0 0 0
0 0 0 4 0 0
0 0 0 0 6 0
0 0 0 0 0 11]

답변 (1개)

Stephen23
Stephen23 2020년 4월 21일
>> M = [1,5,6,1,2,5;7,9,11,3,4,6];
>> V = nan(1,6);
>> V(M(:,4:6)) = M(:,1:3);
>> AA = diag(V)
AA =
1 0 0 0 0 0
0 5 0 0 0 0
0 0 7 0 0 0
0 0 0 9 0 0
0 0 0 0 6 0
0 0 0 0 0 11

카테고리

Help CenterFile Exchange에서 Configure Simulation Conditions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by