How to calculate max. matrix row number

1 回表示 (過去 30 日間)
Ali
Ali 2016 年 6 月 2 日
コメント済み: Ali 2016 年 6 月 2 日
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;
  1 件のコメント
Ali
Ali 2016 年 6 月 2 日
Thank you very much Andrei Bobrov.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by