function find() sometimes doesn’t work properly
hello! i have a simple part of code, but in some cases function find doesnt work
f = [10 : 0.001 : 60];
frez = [48.7234 48.4347 46.4930 46.7682 44.9716 45.9232 48.2044 47.7394 55.0087 49.9675];
for i = 1 :length(frez)
x1 = find(f == round(frez(i)-5, 3));
x2 = find(f == round(frez(i)+5, 3));
Sd{i} = {x1 x2};
end
Sd{3}, Sd{8}, Sd{9} have 1 empty value! Why?
round(frez(3)-5, 3)
ans =
41.4930
>> find(f==ans+0.001)
ans =
31495
>> f(31494)
ans =
41.4930
But that code work!
Why ‘find’ doesnt find index even though it is?hello! i have a simple part of code, but in some cases function find doesnt work
f = [10 : 0.001 : 60];
frez = [48.7234 48.4347 46.4930 46.7682 44.9716 45.9232 48.2044 47.7394 55.0087 49.9675];
for i = 1 :length(frez)
x1 = find(f == round(frez(i)-5, 3));
x2 = find(f == round(frez(i)+5, 3));
Sd{i} = {x1 x2};
end
Sd{3}, Sd{8}, Sd{9} have 1 empty value! Why?
round(frez(3)-5, 3)
ans =
41.4930
>> find(f==ans+0.001)
ans =
31495
>> f(31494)
ans =
41.4930
But that code work!
Why ‘find’ doesnt find index even though it is? hello! i have a simple part of code, but in some cases function find doesnt work
f = [10 : 0.001 : 60];
frez = [48.7234 48.4347 46.4930 46.7682 44.9716 45.9232 48.2044 47.7394 55.0087 49.9675];
for i = 1 :length(frez)
x1 = find(f == round(frez(i)-5, 3));
x2 = find(f == round(frez(i)+5, 3));
Sd{i} = {x1 x2};
end
Sd{3}, Sd{8}, Sd{9} have 1 empty value! Why?
round(frez(3)-5, 3)
ans =
41.4930
>> find(f==ans+0.001)
ans =
31495
>> f(31494)
ans =
41.4930
But that code work!
Why ‘find’ doesnt find index even though it is? find, function, indexing, matlab code, floating point MATLAB Answers — New Questions