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.

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 16 日
編集済み: Azzi Abdelmalek 2013 年 12 月 16 日

0 投票

K = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
nr=1;
nc=1;
K(nr,:)=[]
K(:,nc)=[]
nr1=4;
nc1=4;
K(nr1-1,:)=[];
K(:,nc1-1)=[]

1 件のコメント

ankur
ankur 2013 年 12 月 16 日
wow! Thank you very much Azzi. It works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索

質問済み:

2013 年 12 月 16 日

コメント済み:

2013 年 12 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by