フィルターのクリア

Strange problem with function 'find'

2 ビュー (過去 30 日間)
Jonasz
Jonasz 2013 年 11 月 9 日
コメント済み: Jonasz 2013 年 11 月 9 日
Hello. I have a strange problem with function find. I have this function in for loop and I use it eg. 50 times. This function not always find what I am looking for although if I run this outside the loop it will find my value.
Code:
for i=1:n,
fid=fopen(names(i,1).name);
spec=cell2mat(textscan(fid,'%f %f'))';
fclose(fid);
X=spec(1,:);
Y=spec(2,:);
for j=1:size(setX,1),
x=setX(j,1);
[M,N]=find(X==x); - problem sometimes in this place
if(isempty(M))
DataX(j,i)=0;
else
DataX(j,i)=Y(M,N);
end
end
end
Also I will show you the Data X file (in this place Data Y but it's the same problem - same data).
You can see that in 30 ,33 and 37 loop it didn't find the X value but this value exist and the pattern is the same as others. What it the problem?

採用された回答

Matt J
Matt J 2013 年 11 月 9 日
編集済み: Matt J 2013 年 11 月 9 日
Use a tolerance to allow for floating point errors,
[M,N]=find(abs(X-x)<=somethingsmall)
where "somethingsmall" is small but >0
  1 件のコメント
Jonasz
Jonasz 2013 年 11 月 9 日
Thank You very much !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by