extracting nonpivot columns from a matrix

22 ビュー (過去 30 日間)
Seungryul Lee
Seungryul Lee 2022 年 10 月 1 日
回答済み: dpb 2022 年 10 月 1 日
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!

採用された回答

dpb
dpb 2022 年 10 月 1 日
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 件)

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by