Creating an Indicator Vector

8 次查看(过去 30 天)
Alex Wieseler
Alex Wieseler 2020-9-16
So I am wondering how I create an indicator vector using pivot columns that I stored. Essentially I have created a varible, 'pivot' that stores the columns,c, where there is a pivot entry at.
Example: If the matrix is [1 0 0 0 0; 0 0 1 0 0; 0 0 0 0 1] pivot = [1,3,5]
Now since I found those pivots I want to create an indicating vector using these column values... so if I have a vector called indvect = zeros(1,n), I want to add 1 to the columns of that indvector where there is a pivot...
Example: pivot =[1,3,5] indvector = zeros(1,n)
I want the indvector to be [1 0 1 0 1]
Any help is much appreciated
My code is below
function B= NullBasis(A)
indvector= zeros
thresh = 1e-6
[m n]= size(A);
r=0;
A=rref(A)
for r=1:1:m
r
c=1
if A(r,:)* A(r,:)'> thresh
while abs(A(r,c))< thresh && c<n
c=c+1;
end
end
pivot(r) = c
end
end

回答(1 个)

madhan ravi
madhan ravi 2020-9-16
indvector(pivot) = 1

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by