'find' returning empty vector
26 次查看(过去 30 天)
显示 更早的评论
I've written this section of code:
for k=0.05:0.05:38
index=find(A(:,2)==k);
c=max(A(index,1));
end
but for k=37.7, it returns index as a 0x1 empty double column vector. For all other values of k it works. However, when I simply do:
index=find(A(:,2)==37.7);
it returns a number. Any ideas why the loop won't? Thanks
1 个评论
Stephen23
2022-6-14
"Any ideas why the loop won't?"
For more discussions on this topic:
This is worth reading as well:
采纳的回答
KSSV
2022-6-14
tol = 10^-3 ;
index=find(abs(A(:,2)-37.7)<tol);
Read about comparing floating point numbers.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!