Related to finding columns of a matrix satisfying specific conditions
Show older comments
Hello all,consider the 8 X 4 matrix whose columns are shown below: (Note: Actually we have a large matrix of dimension 8 X 500, but for simplicity we are considering 8 X 4 matrix).
My query is how to find the columns in which only the 3rd and 5th row are non-zero while all other rows are zero.
Any help in this regard will be highly appreciated.
% Col 1
0.00000000000000 + 0.00000000000000i
1.50731573207606 + 0.0126629716692995i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
1.05524235130179 - 1.06946690410098i
% Col 2
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.570954576337680 - 0.0694208400277470i
0.00000000000000 + 0.00000000000000i
-0.439792062677585 + 0.906860087559601i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
% Col 3
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
-0.803157531649936 - 0.535481484911063i
0.00000000000000 + 0.00000000000000i
-0.669680856264729 + 0.552075228739879i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
% Col 4
-0.208494084667111 - 0.237272112154493i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
0.00000000000000 + 0.00000000000000i
-0.117364925574855 + 0.139800044597261i
0.00000000000000 + 0.00000000000000i
Accepted Answer
More Answers (1)
Bruno Luong
on 25 Oct 2023
Edited: Bruno Luong
on 25 Oct 2023
% Generate a test matrix
X = rand(8, 500);
X(:,10) = [0 0 3 0 5 0 0 0];
X(:,20) = [0 0 0 0 5 0 0 0]; % won't be detected since X(3,20) is zeros
mask = true(size(X,1),1);
mask([3,5]) = false;
find(all(xor(mask, logical(X)), 1))
1 Comment
chaaru datta
on 25 Oct 2023
Categories
Find more on Logical 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!