Ensamblar varias submatrices en una matriz

8 Ansichten (letzte 30 Tage)
Isabel Aldana Benavides
Isabel Aldana Benavides am 21 Apr. 2020
Beantwortet: Stephen23 am 21 Apr. 2020
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]

Antworten (1)

Stephen23
Stephen23 am 21 Apr. 2020
>> 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

Kategorien

Mehr zu Configure Simulation Conditions finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by