MATLAB Answers

0

Finding the index (rank) of a specific number from a column

Asked by Abbi Hashem on 10 Dec 2018
Latest activity Commented on by Abbi Hashem on 10 Dec 2018
Suppose I have a column B = [ 1 4 8 3 5 9]
and I have another vector = [ 8]
In this case, I want to find the rank where it's matched in the vector which should return a value of 3 (3rd). How do I do that ?

  3 Comments

why do you say it returns 3?
if you look at the vector , the 1st value is 4 , second is 4 , third is 8 ... the "3 " as in third value is what I want to obain
I got confused because you said rank so you mean index

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 10 Dec 2018
 Accepted Answer

[~, idx] = ismember(8, B)

  3 Comments

What is idx ?
Also, I forgot that the "other vector" is not a vector but just a variable, does this change the code ?
just_a_variable = 8;
[~, rank_that_you_are_looking_for_this_is_the_result_that_you_want] = ismember(just_a_variable, B);

Sign in to comment.