remove all ones from matrix in combinantion
Show older comments
I have A
A=[0 0 0 0 0 0 0 0 0 0;
0 0 0 1 0 1 0 0 0 0;
0 0 0 1 1 0 0 0 0 0;
0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 ];
this matrix has 1 in (R2, R3, R4) and (C4, C5, C6) R correspond to row and C correspond to column.
I want to find combination like below to remove all 1 from matrix. So each R2,R3,R4, C4, C5, C6 should be participate on this.
This is example of combination that I write here. I think it would be better way to do this.
R2 R3 R4 C4 C5 C6
-------------------------------------------------------------------
combination 1: 0 0 0 1 1 1 ---> remove(C4,C5,C6) --> we remove all ones in A (Removed columns or rows is shown by 1)
combination 2: 0 0 1 1 1 1 ---> remove(R4,C4,C5,C6) --> we remove all ones in A
combination 3: 0 1 0 1 0 1 ---> remove(R3,C4,C6) --> remove all ones in A
combination 4: 0 1 1 1 0 1 ---> remove(R3,R4,C5,C6) --> remove all ones in A
combination 5: 1 0 0 1 1 1 ---> remove(R2,C4,C5,C6) --> remove all ones in A
combination 6: 1 0 1 1 1 0 ---> remove(R2,R4,C4,C5) --> remove all ones in A
I do not know how to remove ones from matrix A, by using this combination.
10 Comments
Ameer Hamza
on 6 Mar 2020
Is the matrix A constant, or it can also change? Also, in this case, also give an example of a combination that is not acceptable.
dpb
on 6 Mar 2020
Well, I thought maybe by rearranging the matrix to see its shape and content would be able to figure out what your other table is supposed to mean and just what it is you are trying to do...unfortumately, it didn't help; I have no klew.
While I can agree there are ones in rows 2,3,4 and columns 4,5,6 I can't decipher what the table means nor what you mean by "remove all ones in A" for the "combinations".
You can replace all 1's in A w/ NaN or some other value easily enough with
A(A==1)=nan;
or you can remove rows, columns that contain 1's in their entirety as
A(:,any(A))=[]; % remove all rows w/ 1's
A(any(A,2),:)=[]; % remove any remaining columns if any
but you can't leave "holes" in the middle of an array.
So, tell/show what you think the result should be and how you arrived at that result.
the cyclist
on 6 Mar 2020
Edited: the cyclist
on 6 Mar 2020
I think I understand what you are trying to do. For example, another combination that removes all 1's from A would be
remove(R2,R3,R4)
wiithout needing to mention columns. Because 1's only appear in rows 2, 3, and 4. Right?
How do you want the output reported? Suppose that your combination 1 and 2 were the only ones that worked. Would the output be a matrix like this?
output = [0 0 0 1 1 1
0 0 1 1 1 1];
That doesn't really tell you that the columns correspond to R2 R3 R4 C4 C5 C6. Is that OK?
Suppose
A = [0 0 0;
0 1 0;
0 0 1];
What is the full output that you want?
the cyclist
on 6 Mar 2020
So, for others' sake, here is what I think OP wants:
Find every combination of rows and columns such that, if I remove those rows and columns, there will be no 1's in the matrix. So, for example, if
A = [0 0 0;
0 1 0;
0 0 1];
the combinations would be
R2,R3
R2,C3
R3,C2
I'm just not certain how OP wants the output structured.
the cyclist
on 6 Mar 2020
Edited: the cyclist
on 6 Mar 2020
I don't yet understand the operation you want to do on B. But it sounds like if
A = [0 0 0;
0 1 0;
0 0 1];
then all possible solutions are
removed_index_all_rows={[2,3];[2,3];[2,3]}; % Has the redundant rows
but you don't need redundant rows, so
removed_index={[2,3]}; % Keep only unique rows
Also, can you confirm that removing
remove(R4,C4,C5,C6)
and
remove(C4,C5,C6)
are truly redundant, even though the first one has row 4, and the second one has only column 4? They would both give
removed_index={[4,5,6]};
?
Guillaume
on 6 Mar 2020
I wrote my solution before seeing the updates. I'm still unclear on exactly what you're trying to achieve. Two common problem that appear to be related are the Maximum coverage problem and the set cover problem. Is this what you're after?
As explained, my solution will find all the covers. However, it's easy to change the recursion function so that it discards covers that fully encompass other covers.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!