How can I find index and matched value in vector

7 views (last 30 days)
Vector = [ -0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.3315];
[row,col,v] = find(abs(Vector)>=0.0001)
row =
32
col =
1
v =
1
Index(row) is 32 and v = 1. But true value is -0.3315.
How can I find index and matched value in vector?

Accepted Answer

Stephen23
Stephen23 on 21 Jan 2016
Edited: Stephen23 on 21 Jan 2016
>> Vector(row,col)
ans = -0.33150
Or if you do not need the index then you can use logical indexing:
>> Vector(abs(Vector)>=0.0001)
ans = -0.33150
  2 Comments
Stephen23
Stephen23 on 21 Jan 2016
Edited: Stephen23 on 21 Jan 2016
EDIT: the OP originally asked how the Answer works.
I simply used the indices from find, that your code has too:
[row,col] = find(abs(Vector)>=0.0001);
and then use those indices to get the value from the original vector:
Vector(row,col)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!