extracting nonpivot columns from a matrix
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have a function nonpuvotcols that takes a matrix as input and produces a matrix consisting of the nonpivot columns. For the last step of my code, I need to extract all the nonpivot colums from the input matrix, but I think I'm only extracting the last nonpivot column from the matrix.
% Returns the nonpivot columns from the matrix A
function npc = nonpivotcols(A)
% determine n the number of columns of A
[m, n_plus_one] = size(A)
n = n_plus_one-1
% use rref to obtain a list of the pivot columns of A (pcols)
[R pcols]=rref(A);
A(:,pcols)=[];
% from the list of all columns 1:n remove pcols to obtain a list of the nonpivot columns (fcols)
%% Getting columns which if fcol
[r,fcols]=size(A);
%(HELP) extract the nonpivot columns from A
npc = A(:,fcols);
end
This is my code. Please help me for the last commented part, which is to extract all the nonpivot columns.
A = [ 1 1 2 2 3 3; 4 4 5 5 6 6; 7 7 8 8 9 9]
[R, pcols] = rref(A)
nonpivotcols(A)
And here is the code to call the function.
Thank you!
0 Kommentare
Akzeptierte Antwort
dpb
am 1 Okt. 2022
function npc = nonpivotcols(A)
[~,p]=rref(A);
A(:,pcols)=[];
npc=A;
end
or
function npc = nonpivotcols(A)
[~,p]=rref(A);
npc=A(:,setdiff(1:size(A,2),p));
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!