How to calculate max. matrix row number

1 次查看(过去 30 天)
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

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-6-2
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;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by