Relation of Elements of matrix
Show older comments
A = [1 2
2 6
2 3
2 7
3 4
5 4
6 3
4 7]
i have matrix A,
if i select B=2, i want output as 1 2 3 6 7, it shows relatiionship of 2
if i select B=3, i want output as 2 3 4 6, it shows relatiionship of 3
1 Comment
KSSV
on 29 Jan 2021
What do you mean by relationship of 2? What is B?
Accepted Answer
More Answers (1)
Paul Hoffrichter
on 29 Jan 2021
B = 3;
[r, ~] = ind2sub( size(A), find(A==B) );
z = A(sort(r),:);
zu = unique(z(:))'
2 Comments
Paul Hoffrichter
on 29 Jan 2021
B = 2;
[r, ~] = ind2sub( size(A), find(A==B) );
z = unique( A( sort(r) ,: ) )'
Paul Hoffrichter
on 29 Jan 2021
Don't need the sort, so this is faster:
[r, ~] = ind2sub( size(A), find(A==B) );
z = unique( A( r ,: ) )'
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!