find the element in matrix of intersecting vectors

3 ビュー (過去 30 日間)
Ani Asoyan
Ani Asoyan 2020 年 1 月 23 日
コメント済み: Ani Asoyan 2020 年 1 月 23 日
Here's my code. I have а & b matrices, and A & B vectors that maximize a's rows and b's colums. also there is another matrix that is a combination of these two matrices ( c ).
I want to have such a result that the intersection of A and B vectors will give the corresponding element from c
For example if
A(1)=a(2,1) & A(2)=a(2,2)
B(1)=b(1,2) & B(2)=b(2,2)
THUS the result is c(2,2)
a=[1,2;3,4]
b=[5,6;7,8]
for i=1:2
A(i)=max(a(:,i))
B(i)=max(b(i,:))
end
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 23 日
Sorry I donot geting the question?
Ani Asoyan
Ani Asoyan 2020 年 1 月 23 日
ok here's the thing.
I have two matrices.
a=[1, 2; 3, 4]
b=[5, 6; 7, 8]
and I maximize 'a' matrix's rows
A(1)=max(a(:,1))
A(2)=max(a(:,2))
and maximize 'b' matrix's colums
B(1)=max(b(1,:))
B(2)=max(b(2,:))
now I have 2 vectors` A and B
Also I combine a and b matrices and get another matrix named c (sorry I didn't include it in the code back then)
endnum2strcell = @(m) arrayfun(@num2str, m, 'UniformOutput', false);
c=strcat(num2strcell(a), num2strcell(b))
Here's the question
I want to get the element of intersection of 'A' and 'B' vectors, and I want it to find in c matrix.
For example. If
A(1)=a(1,1)
A(2)=a(1,2) ('A' vector will be 'a' matrix's 1st column)
B(1)=b(1,2)
B(2)=b(2,2) ('B' vector will be 'b' matrix's 2nd row)
then the result will be c(1,2)

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

採用された回答

Matt J
Matt J 2020 年 1 月 23 日
編集済み: Matt J 2020 年 1 月 23 日
attainedA=( max(a,[],1)==a );
attainedB=( max(b,[],2)==b );
result = c(attainedA & attainedB)
  1 件のコメント
Ani Asoyan
Ani Asoyan 2020 年 1 月 23 日
OMG thank you so much !! This is exactly what I wanted!!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by