开发者

Chop out parts of a square matrix in Matlab

开发者 https://www.devze.com 2022-12-21 19:59 出处:网络
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:

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/814开发者_如何转开发5/cutmatrix.png


Here are two simple solutions:

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

or:

x(k,:)=[];x(:,k)=[];


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


Not a builtin function, but the following line does the trick:

y = [x(1:(k-1),1:(k-1)) x(1:(k-1),(k+1):end) ; x((k+1):end,1:(k-1)) x((k+1):end,(k+1):end)];
0

精彩评论

暂无评论...
验证码 换一张
取 消