Creating an Indicator Vector

9 views (last 30 days)
Alex Wieseler
Alex Wieseler on 16 Sep 2020
Commented: Alex Wieseler on 16 Sep 2020
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

Answers (1)

madhan ravi
madhan ravi on 16 Sep 2020
indvector(pivot) = 1

Categories

Find more on Interpolation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!