How can I find index and matched value in vector

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?

 Risposta accettata

Stephen23
Stephen23 il 21 Gen 2016
Modificato: Stephen23 il 21 Gen 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 Commenti

DongShin Yang
DongShin Yang il 21 Gen 2016
Modificato: DongShin Yang il 21 Gen 2016
Thank your help.
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)

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by