File Exchange

image thumbnail


version (1.3 KB) by Gordon Amoako
This is a function that computes the cofactors of an n x n matrix


Updated 10 Sep 2010

View Version History

View License

When a user enters an n x n matrix eg. A=[1 1 1; 3 1 -1; 2 1 -1] the function computes the corresponding cofactors.

Cite As

Gordon Amoako (2021). cofactors (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Lateef Kareem

Another issue with bruno's suggestion is that we still have to take the transpose of the result to get the cofactor matrix


Bruno's suggestion only works for invertible matrices

Bruno Luong

Cofactor_of_a = inv(a).'*det(a)

Simpler and faster.


Sean de

The output is not preallocated and grows inside the loop: M-LINT!!!

This will do the same thing faster (with preallocating output):
[rr cc] = meshgrid(1:r,1:c);
D = zeros(r,c);
for ii = 1:numel(A)
D(ii) = det(A(~(rr(ii)==1:r),~(cc(ii)==1:c)));
Ab = (-1).^(rr+cc).*D';

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!