Lets say we have an array
20 4
21 5
22 3
23 2
24 1
25 2
26 7
if that table say =x how do I return a value in the first row from the second for example if I have x(:,2)==7 give ans=26 (first column corresponding to 7). Another example would be x(:,2)==2 give ans=25 Thanks

답변 (1개)

Jan
Jan 2015년 10월 24일

0 개 추천

x = [20 4; ...
21 5; ...
22 3; ...
23 2; ...
24 1; ...
25 2; ...
26 7]
search = 2;
index = (x(:, 2) == search);
result = x(index, 1)

댓글 수: 3

James Connor
James Connor 2015년 10월 24일
Is it possible to do it by only considering rows. Like 2 is on the 6th row thus output 25?
James Connor
James Connor 2015년 10월 24일
Sorry I didnt explain my question well, I mean for like max(x(:,2)); which would be 7 thus output a value of 26.
Jan
Jan 2015년 10월 25일
Perhaps you mean:
[value, index] = max(x(:, 2));
x(index, 1)

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

카테고리

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

질문:

2015년 10월 24일

댓글:

Jan
2015년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by