result of ismember is wrong in my code correct in command window

5 次查看(过去 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,

采纳的回答

James Tursa
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
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by