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

조회 수: 2 (최근 30일)
nadia nadi
nadia nadi 2015년 12월 3일
편집: Stephen23 2015년 12월 5일
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
nadia nadi
nadia nadi 2015년 12월 4일
Thank you very much, it was all good advice. I appreciate all of you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by