deleting rows and columns
Afficher commentaires plus anciens
lets say if matrix K = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
if i use:
rows2remove=[1]; ....1
cols2remove=[1]; ....2
K(rows2remove,:)=[] ....3
K(:,cols2remove)=[] ....4
rows2remove=[4]; ....5
cols2remove=[4]; ....6
K(rows2remove,:)=[] ....7
K(:,cols2remove)=[] ....8
at line 4, it removes the 1st row and 1st column of the matrix K. then, it gives an error ' Index of element to remove exceeds matrix dimensions'. that's because the new matrix is 3 by 3 after executing the line 4. how do i delete 1st row 1st column and then 4th row 4th column of original matrix K?
i could have used
rows2remove=[1 4];
cols2remove=[1 4];
K(rows2remove,:)=[]
K(:,cols2remove)=[]
but how can i delete the row-column pair individually? what i mean is i would like to 'delete 1st row 1st column' so that i get a 3 by 3 matrix. then the next operation 'deleting 4th row 4th column' from the original matrix K so that finally i get a required 2 by 2 matrix [6 7; 10 11]?
i hope you understand my question. it's bit confusing i guess.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Operating on Diagonal Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!