extracting nonpivot columns from a matrix
12 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!