Finding Data in a loaded file

10 vues (au cours des 30 derniers jours)
Rohan  Mehta
Rohan Mehta le 10 Juil 2019
Commenté : Guillaume le 10 Juil 2019
I am having a data file with amplitudes mentioned in it almost 10000 samples are present and I know value of one amplitude which is present in the data and want to find location of that sample how to do that ?

Réponse acceptée

Ruben Costa
Ruben Costa le 10 Juil 2019
Hello,
find(NameOfMatrix==ValueThatYouknow)
This will give you the exact position of the value that you want in the matrix that you have! If you want, you can use any condition to know the position of other values!
Hope it helps!
  1 commentaire
Guillaume
Guillaume le 10 Juil 2019
Modifié(e) : Guillaume le 10 Juil 2019
Depending on what is to be done afterward, the find may not be necessary. The logical vector returned by the comparison may be enough.
Note that == does exact comparison and may therefore not work as expected if the data stored in the matrices is not integer. See for example:
>> (0.3-0.2-0.1) == 0 %is false
ans =
logical
0
For floating point numbers, you would be better off using the method shown by KSSV (with an appropriate tolerance) or ismembertol.

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 10 Juil 2019
Let A be your data and you want to seek b from it.
idx = find(abs(A-b)<10^-5)
  3 commentaires
KSSV
KSSV le 10 Juil 2019
It is a tolerance set, to check the equality of both numbers. This is how the floating numbers are checked.
Guillaume
Guillaume le 10 Juil 2019
10^-5 is better written as 1e-5 (1e-5 does not involve any runtime computation).
It must be pointed out that the comparison tolerance must be chosen in accordance to the magnitude of the numbers being compared. 1e-5 would be completely inapproriate if the magnitude of the numbers being compared is in the order of 1e-10.
For that reason, ismembertol would be better as it automatically calculate the appropriate tolerance for you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by