Find the position index of vector array
7 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!