Find the position index of vector array

7 views (last 30 days)
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?

Accepted Answer

Stephan
Stephan on 26 May 2018
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 Comments
Brendan Chou
Brendan Chou on 27 May 2018
Edited: Brendan Chou on 27 May 2018
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?
Stephan
Stephan on 28 May 2018
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

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!