필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by