Getting 1 value from another.
Afficher commentaires plus anciens
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 commentaire
Jan
le 24 Oct 2015
Why not 23 for the value 2?
Réponses (1)
Jan
le 24 Oct 2015
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 commentaires
James Connor
le 24 Oct 2015
James Connor
le 24 Oct 2015
Jan
le 25 Oct 2015
Perhaps you mean:
[value, index] = max(x(:, 2));
x(index, 1)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!