How to calculate max. matrix row number

1 visualizzazione (ultimi 30 giorni)
Ali
Ali il 2 Giu 2016
Commentato: Ali il 2 Giu 2016
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

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 2 Giu 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;

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by