Find row in a matrix A corresponding to the row another matrix B

1 回表示 (過去 30 日間)
Ricardo Gutierrez
Ricardo Gutierrez 2018 年 7 月 9 日
回答済み: Ricardo Gutierrez 2018 年 7 月 9 日
Good Morning.
I hope you are well and also I hope you help me with your advice to find the solution.
I have an A matrix of 6 X 10 as an example:
-1.3726 -0.7760 -0.6715 -0.2796 -0.1499 0.1499 0.2796 0.6715 0.7760 1.3726
-1.3726 -0.7760 -0.6715 -0.1796 -0.0499 0.0499 0.1796 0.6715 0.7760 1.3726
-1.3726 -0.7760 -0.7715 -0.2796 -0.0499 0.0499 0.2796 0.7715 0.7760 1.3726
-1.3726 -0.7760 -0.6715 -0.2796 -0.0499 0.0499 0.2796 0.6715 0.7760 1.3726
-1.3726 -0.8760 -0.6715 -0.2796 -0.0499 0.0499 0.2796 0.6715 0.8760 1.3726
-1.4726 -0.7760 -0.6715 -0.2796 -0.0499 0.0499 0.2796 0.6715 0.7760 1.4726
Each row is taken for a certain operation resulting in a matrix B_ 6 X 1:
B=[13.01; 13.14; 16.60; 20.05; 13.74; 12.48]
The first row of matrix A produces the first row of matrix B
The second row of matrix A produces the second row of matrix B and so on
The problem is that through Matlab code identify the maximum value and the posicon of vector B and know what elements of the row and position of that line of matrix A corresponds to it.
In this case it is visually known that the maximum in B is 20.05 and that it occupies the 4th row of the same matrix and therefore corresponds to the fourth row of matrix A with elements that are in that row, that is: -1.3726 -0.7760 -0.6715 -0.2796 -0.0499 0.0499 0.2796 0.6715 0.7760 1.3726
That's what I want to know: value and position of the maximum of B and position and values of the elements of vector A that produced that maximum value in B
I hope you have understood me and I am waiting for your help. Thank you.

採用された回答

Paolo
Paolo 2018 年 7 月 9 日
編集済み: Paolo 2018 年 7 月 9 日
If I am understanding the question correctly the answer is simply:
>>C = A(B==max(B),:)
C = Columns 1 through 7
-1.3726 -0.7760 -0.6715 -0.2796 -0.0499 0.0499 0.2796
Columns 8 through 10
0.6715 0.7760 1.3726

その他の回答 (1 件)

Ricardo Gutierrez
Ricardo Gutierrez 2018 年 7 月 9 日
Paolo Excellent you are a genius, thank you very much

カテゴリ

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

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by