How to calculate max. matrix row number
1 view (last 30 days)
Show older comments
I have A and B matrices. I would like to write a code to calculate Max. row' number between 1 4 and 4 1.
Matrix A has 300 rows with 3 columns. Matrix B has 500 rows and 2 columns. row's number in Matrix B start from 0.
A= [4 1 6]
B= [4 1
1 6
1 4
6 1
6 4
4 6]
max row's number between 1 4 and 4 1 = 2
please help me with this issue, if you know how to solve this.
thanks
0 Comments
Accepted Answer
Andrei Bobrov
on 2 Jun 2016
m = size(A,2);
Y1 = reshape(permute(cat(3,A,circshift(A,[0 -1])),[3,2,1]),size(A,1),[]); %
Y2 = flip(Y1,1);
Bp = permute(B,[2,3,1]);
X = reshape(any([all(bsxfun(@eq,Y1,Bp));all(bsxfun(@eq,Y2,Bp))]),m*2,[])';
Z = reshape(max(bsxfun(@times,X,(1:size(B,1))')),m,[])'-1;
More Answers (0)
See Also
Categories
Find more on NaNs 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!