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

2 visualizaciones (últimos 30 días)
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,

Respuesta aceptada

James Tursa
James Tursa el 3 de Dic. de 2015
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 comentarios
Star Strider
Star Strider el 4 de Dic. de 2015
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
nadia nadi
nadia nadi el 4 de Dic. de 2015
Thank you very much, it was all good advice. I appreciate all of you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by