result of ismember is wrong in my code correct in command window
2 次查看(过去 30 天)
显示 更早的评论
Dear, I have this code, when I get the result from the loop I find the common rows between pp and pointsout but I got wrong result, when I copy my matrix pp and pointsout to command window or I comment my code and tried from file it gives correct answer. for example
pp =[
29.6360 20.2328 25.8546
22.0039 27.8829 29.8251
23.3343 26.8422 20.0174
20.1460 29.4970 29.2674
27.7054 29.9161 24.0945
29.9539 27.4832 29.3899];
pout=[];
pin=[];
points=pp;
for k=1:size(pp,1)
[ClosestPoint,Distance] = Cl(XYZ,pp(k,:));
if Distance ==-2
pin=[pin; pp(k,:)]
end
pout=[pout; ClosestPoint];
end
pointsout=[pointsin; pout];
% find the index of the in points
idx=ismember(pointsout ,points,'rows')
if
pointsout =[
33.6612 39.8834 33.3147
25.2505 41.9976 32.2839
25.6122 41.9067 32.3282
23.0877 42.5413 32.0188
29.4130 40.9513 32.7941
32.6676 40.1332 33.1929];
it gives me just five rows by ismemebr, when I take the two matrices and check in the command window I get 6 rows even when I comment the code to check. What is wrong of the code, why it effect the result. I'm sorry I can't write the whole code for respect to function Cl its 4 files. Thanks for any comments and help.
Nadia,
0 个评论
采纳的回答
James Tursa
2015-12-3
I suspect this is just floating point issues. Reading from a file may read in all of the precision of the numbers (i.e., precision beyond the 4 digits after the decimal point you are showing). But setting the numbers directly from the command line as in your code above may give you slightly different results. I suggest you check and compare the pp and pointsout etc you get from the various methods you are using to see if there are any differences.
7 个评论
Star Strider
2015-12-4
You can emulate the most recent round function with this one:
roundn = @(x,n) round(x .* 10.^n)./10.^n; % Round ‘x’ To ‘n’ Digits
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!