MATLAB Answers

finding indices of values in a range

20 views (last 30 days)
sparsh garg
sparsh garg on 20 Sep 2021 at 6:52
Commented: sparsh garg on 20 Sep 2021 at 9:06
let's say you have a 2x300 matrix A,from that matrx,i select a sub array of dimension 2x24 whose range is as follows
[18 :41]
Now you have another matrix B which is an unordered version of the previous matrix.Meaning that value located at idnice 1 in A can be found in B at say 150.
How do i go about fidning at which indices do the values in the range of A occur in B
  1 Comment
sparsh garg
sparsh garg on 20 Sep 2021 at 7:32
i tried using intersect but it didn't give me satisfactory results
for eg in the matrices shown below
the correct location of the values in query in the original matrix is
34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 80 82
similarly for query_2 the indices
are 33 35 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81

Sign in to comment.

Answers (1)

KSSV
KSSV on 20 Sep 2021 at 7:31
To achieve the first task, you can use inqualities i.e. >, <. = etc.
To achieve the second task use ismember.
  1 Comment
sparsh garg
sparsh garg on 20 Sep 2021 at 9:06
so what you are saying is i first do [~,idx]=find(original_matrix==query_matrix),
but the original matrix has 2 duplicates for every value in query_matrix.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!