Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Subscript assignment mismatch with the use of 'find'

1 Ansicht (letzte 30 Tage)
aditya
aditya am 31 Aug. 2011
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
The following as commands typed in the command window with the results:
>> X = 0:0.001:1;
>> find(X==0.57)
ans =
Empty matrix: 1-by-0
>> X(571)
ans =
0.5700
I cannot figure out why find doesn't work. I stumbled on it accidentally. This works if choose to find any other number except a special few like 0.47, 0.67, 0.41...

Antworten (3)

Arturo Moncada-Torres
Arturo Moncada-Torres am 31 Aug. 2011
I recommend you to look at this part of the MATLAB FAQ. This explains the results you are getting.

Fangjun Jiang
Fangjun Jiang am 31 Aug. 2011
floating point comparison!!!

aditya
aditya am 31 Aug. 2011
Thanks. But in that case...using '==' should not give a result for a lot more cases.
Also,
using linspace instead of colons for defining the vector (here, X) seems to solve the problem. I do not like the approach of comparing difference with tolerance as given in the FAQ...it is not really a good solution in my opinion.
  1 Kommentar
Walter Roberson
Walter Roberson am 2 Sep. 2011
Using tolerances is the only practical solution unless you have a system that has extensive interval-arithmetic operations built in. Building in that level of interval-arithmetic is hard!!

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by