how to find common values in two matrix for particular column?
Show older comments
if true
% code
A=[0 1 1 0; 1 0 0 1; 1 1 0 0; 0 0 1 1]
B=[0 1 0 1; 1 0 1 0; 0 0 1 1; 1 1 0 0]
end
for 1st column of A and ALL columns of b
if we check
the expected answer is
1 0 2 1
these are the total number of instances they are matching
3 Comments
madhan ravi
on 24 Oct 2018
1 0 2 1 explain the logic please
Bruno Luong
on 24 Oct 2018
Please put care on
- code formatting
- explanation
- formulation of synthetic question (Why give the whole A and ask just result that depends only on first column)
Shubham Mohan Tatpalliwar
on 24 Oct 2018
Accepted Answer
More Answers (1)
Stephen23
on 24 Oct 2018
You don't need to use a loop:
>> sum(permute(A,[3,2,1])&permute(B,[2,3,1]),3)
ans =
1 0 1 2
0 1 2 1
2 1 0 1
1 2 1 0
1 Comment
Shubham Mohan Tatpalliwar
on 24 Oct 2018
Categories
Find more on Shifting and Sorting 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!