Find function in Matlab
显示 更早的评论
Dear all ,
I have problem with this code
clc
close all
Signal = Hole1_mid;
Compare(:,1)=Signal(:,2);
value1 = 1.9752;
index1 = find(ismember(Compare,value1),n);
Hole1_6m(:,end) = Signal(1:index1,end);
Find function is not working in this case and I have no idea why
2 个评论
Rik
2017-12-19
What would you mean with 'not working'? If it is a true bug, it is very unlikely it wouldn't have been found yet in a popular function like find, but it's not impossible. If not a bug, you must not be understanding what it does.
Try to create a stand-alone piece of code we can run to replicate what you have. Point out what you get, and how it differs from what you want.
"Find function is not working in this case"
Actually it is working correctly.
"and I have no idea why"
Your code tests for equivalence of floating point values, which is a very buggy and unreliable way to write code. You need to change your algorithm to take into account floating point error:
and a thousand other threads where this has been discussed. You could easily have searched this forum yourself and found many answers telling what is happening. This is worth reading as well:
采纳的回答
更多回答(1 个)
Walter Roberson
2017-12-19
1 个投票
1.9752 is not exactly representable in binary floating point, so there is a good chance that whatever value is in Compare is not exactly the same as the bit-for-bit exact value stored in value1
Consider using ismembertol()
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!