Hi I am trying to find the position of a vector array. After I have found the maximum value in the first and third row, and the minimum value in the second row, how can I get the position index to be applied on the other variable as they correspond to the same position?

 채택된 답변

Stephan
Stephan 2018년 5월 26일

0 개 추천

Hi,
you can use the code from the following example for your purpose:
A = [1 2 3 10 6 0.999 -3 -5;...
-3 -4 -10 1 2 0.003 -8 10;...
2 3 6 7 9 10 0.2 0.0006];
indices = [find(A(1,:) == max(A(1,:)));...
find(A(2,:) == min(A(2,:)));...
find(A(3,:) == max(A(3,:)))];
this gives you:
A =
Columns 1 through 4
1.0000 2.0000 3.0000 10.0000
-3.0000 -4.0000 -10.0000 1.0000
2.0000 3.0000 6.0000 7.0000
Columns 5 through 8
6.0000 0.9990 -3.0000 -5.0000
2.0000 0.0030 -8.0000 10.0000
9.0000 10.0000 0.2000 0.0006
indices =
4
3
6
Keep in mind that these indexes only reflect the column of the desired row. For further use, the first mentioned index must be addressed as follows:
Value_Row_1 = A(1, indices(1))
Value_Row_3 = A(2, indices(2))
which delivers:
Value_Row_1 =
10
Value_Row_3 =
-10
to make it a little easier use:
values = [max(A(1,:)); min(A(2,:)); max(A(3,:))];
which gives:
values =
10
-10
10
these values you can directly access with:
values(2) % Accessing the minimum value from row 2
ans =
-10
Best regards
Stephan

댓글 수: 2

Brendan Chou
Brendan Chou 2018년 5월 27일
편집: Brendan Chou 2018년 5월 27일
Thanks a lot Stephan! I have another variable with the same size of vector array. Once I have found the maximum and minimum index, I want to reflect it on the same position of the other variable, as they correspond to each other. Therefore may I know how can I correspond the position index on the other variable?
Hi,
other_variable (1, indices (1)) = A (1, indices (1));
other_variable (2, indices (2)) = A (2, indices (2));
other_variable (3, indices (3)) = A (3, indices (3));
Best regards
Stephan

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 5월 24일

댓글:

2018년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by