Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chop out parts of a square matrix in Matlab

Tags:

matrix

matlab

Is there an inbuilt function that removes the Kth row and column of a square matrix in Matlab?

Hope it's clear from the diagram:

alt text http://img121.imageshack.us/img121/8145/cutmatrix.png

like image 247
ntimes Avatar asked Dec 29 '22 00:12

ntimes


2 Answers

Here are two simple solutions:

x([1:k-1 k+1:end],[1:k-1 k+1:end])

or:

x(k,:)=[];x(:,k)=[];
like image 170
Ramashalanka Avatar answered Jan 10 '23 03:01

Ramashalanka


If you want to use this operation more often, creating a function is a good idea.

% filename: removeK.m

function M1 = removeK (M, k)
  M1 = M([1:k-1 k+1:end],[1:k-1 k+1:end]);
end
like image 44
user286405 Avatar answered Jan 10 '23 03:01

user286405