Randomly deleting a 'one' in a column of a binary matrix
Show older comments
Hi,
I have a matrix that looks like this:
1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 1 1
0 0 0 0 0 1
0 0 0 0 0 1
What should I do when I randomly want to delete a 'one' in (let's say) column 4? Thanks in advance,
Tim
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 11 Oct 2012
Edited: Azzi Abdelmalek
on 11 Oct 2012
A=[1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 1 1
0 0 0 0 0 1
0 0 0 0 0 1]
m=size(A,2)
idx=randi(m,1)
A(:,idx)=[] % this will remove column number idx
%I 'm not sur what you mean by delete a one, if you want raplace them by 0
A(:,idx)=0
4 Comments
Tim
on 11 Oct 2012
Wayne King
on 11 Oct 2012
My answer below will change just one of the 1's to a 0.
Azzi Abdelmalek
on 11 Oct 2012
Edited: Azzi Abdelmalek
on 11 Oct 2012
Tim you did'nt read all the answer, at the end I said use
A(:,idx)=0
istead of
A(:,idx)=[]
which means use the below code
m=size(A,2)
idx=randi(m,1)
A(:,idx)=0
Tim
on 11 Oct 2012
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!