Thread Subject: Matlab debugging question

Subject: Matlab debugging question

From: s a

Date: 8 Sep, 2008 12:58:02

Message: 1 of 11

Hello,

I have a strange Matlab behavior, basically I have a pretty large matrix which hold coordinates of two point at each row. When i am given the coordinates of two point I would like to search for them in this large matrix. I just a straight forward way by calculating an euclidean distance and searching for a zero distance. I have an error print out if I do not find matching points. The problem is when the code is running I have many points not found but If i use the SAME code without any changes and just insert a break point on the error message the code run perfectly and locates all the points I need and returns correct results. Nevertheless it doesn't stop at the break point since the points where found. I was wondering if someone had the same phenomena or have some idea how to solve it.

Thanks,
S

Subject: Matlab debugging question

From: Steven Lord

Date: 8 Sep, 2008 13:15:06

Message: 2 of 11


"s a" <shaec47@walla.co.il> wrote in message
news:ga37gq$nch$1@fred.mathworks.com...
> Hello,
>
> I have a strange Matlab behavior, basically I have a pretty large matrix
> which hold coordinates of two point at each row. When i am given the
> coordinates of two point I would like to search for them in this large
> matrix. I just a straight forward way by calculating an euclidean distance
> and searching for a zero distance. I have an error print out if I do not
> find matching points. The problem is when the code is running I have many
> points not found but If i use the SAME code without any changes and just
> insert a break point on the error message the code run perfectly and
> locates all the points I need and returns correct results. Nevertheless it
> doesn't stop at the break point since the points where found. I was
> wondering if someone had the same phenomena or have some idea how to solve
> it.

Let me guess -- when you're "searching for a zero distance", you're doing
something like:

x = find(distance == 0)

More than likely, your distances are very close to but not exactly equal to
0 due to roundoff error caused because the numbers in your matrix cannot be
exactly represented in double precision. For instance, none of 0.1, 0.2, or
0.3 can be exactly represented in double precision, and:

x = 0.1+0.2;
y = x == 0.3

returns false in y.

Instead of performing a check for exact equality, check for the distance to
be less than some tolerance (what that tolerance should be depends on your
data.)

tol = 1e-6;
x = find(abs(distance) < tol);

For more information:

http://www.mathworks.com/support/solutions/data/1-16FOQ.html

http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf

http://docs.sun.com/source/806-3568/ncg_goldberg.html

--
Steve Lord
slord@mathworks.com


Subject: Matlab debugging question

From: s a

Date: 8 Sep, 2008 13:34:02

Message: 3 of 11

"Steven Lord" <slord@mathworks.com> wrote in message <ga38gq$6sa$1@fred.mathworks.com>...
>
> "s a" <shaec47@walla.co.il> wrote in message
> news:ga37gq$nch$1@fred.mathworks.com...
> > Hello,
> >
> > I have a strange Matlab behavior, basically I have a pretty large matrix
> > which hold coordinates of two point at each row. When i am given the
> > coordinates of two point I would like to search for them in this large
> > matrix. I just a straight forward way by calculating an euclidean distance
> > and searching for a zero distance. I have an error print out if I do not
> > find matching points. The problem is when the code is running I have many
> > points not found but If i use the SAME code without any changes and just
> > insert a break point on the error message the code run perfectly and
> > locates all the points I need and returns correct results. Nevertheless it
> > doesn't stop at the break point since the points where found. I was
> > wondering if someone had the same phenomena or have some idea how to solve
> > it.
>
> Let me guess -- when you're "searching for a zero distance", you're doing
> something like:
>
> x = find(distance == 0)
>
> More than likely, your distances are very close to but not exactly equal to
> 0 due to roundoff error caused because the numbers in your matrix cannot be
> exactly represented in double precision. For instance, none of 0.1, 0.2, or
> 0.3 can be exactly represented in double precision, and:
>
> x = 0.1+0.2;
> y = x == 0.3
>
> returns false in y.
>
> Instead of performing a check for exact equality, check for the distance to
> be less than some tolerance (what that tolerance should be depends on your
> data.)
>
> tol = 1e-6;
> x = find(abs(distance) < tol);
>
> For more information:
>
> http://www.mathworks.com/support/solutions/data/1-16FOQ.html
>
> http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf
>
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
>
> --
> Steve Lord
> slord@mathworks.com
>
>
Hi,

I have tried that but still have the same phenomena. Just to be on the safe size I have printed the minimum distance and it is more then 1. So it doesn't seems like a roundoff problem.

Subject: Matlab debugging question

From: us

Date: 8 Sep, 2008 13:44:02

Message: 4 of 11

"s a":
<SNIP breakpoint-blues...

> I have a strange Matlab behavior
> ...If i use the SAME code without any changes and just insert a break point on the error message the code run perfectly...

can you produce a parsimonious snippet, which shows this behavior?

us

Subject: Matlab debugging question

From: John D'Errico

Date: 8 Sep, 2008 13:54:01

Message: 5 of 11

"s a" <shaec47@walla.co.il> wrote in message <ga39ka$kvv$1@fred.mathworks.com>...
> I have tried that but still have the same phenomena. Just to be on the safe size I have printed the minimum distance and it is more then 1. So it doesn't seems like a roundoff problem.

So use a tool that finds the point with the
minimum Euclidean distance. If that distance
is less than a tolerance, then you have found
an acceptable point.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=18937&objectType=FILE

My IPDM code will return the minimum distance,
and tell you which point it was. Or, you can tell
it to only return those points which lie within
your tolerance. You can choose from among
distance metrics too.

John

Subject: Matlab debugging question

From: s a

Date: 8 Sep, 2008 13:56:01

Message: 6 of 11

"us " <us@neurol.unizh.ch> wrote in message <ga3a72$sjl$1@fred.mathworks.com>...
> "s a":
> <SNIP breakpoint-blues...
>
> > I have a strange Matlab behavior
> > ...If i use the SAME code without any changes and just insert a break point on the error message the code run perfectly...
>
> can you produce a parsimonious snippet, which shows this behavior?
>
> us
In a nutshell

       AllPaths=cell2mat(ListScaleNodes{S,1}(SqrIndx));
       AllPaths=unique(AllPaths,'rows');
      for n=1:size(pTemp,1)
               z=pTemp(n,:);
               
               TP=sum((AllPaths(:,1:4)-z(ones(size(AllPaths,1),1),:)).^2,2);
               TTEIdx=TP<=1e-5;
               TTE=nnz(TTEIdx);
            
               if (TTE==0)
                fprintf('PAth not found! please check code') ;
               else
....

Subject: Matlab debugging question

From: Bruno Luong

Date: 8 Sep, 2008 13:57:03

Message: 7 of 11

"us " <us@neurol.unizh.ch> wrote in message <ga3a72$sjl$1@fred.mathworks.com>...
> "s a":
> <SNIP breakpoint-blues...
>
> > I have a strange Matlab behavior
> > ...If i use the SAME code without any changes and just insert a break point on the error message the code run perfectly...
>

I have encounted a similar issue with a script running in cell mode. Though I don't have a recollection of the details.

Bruno

Subject: Matlab debugging question

From: s a

Date: 8 Sep, 2008 14:00:20

Message: 8 of 11

"us " <us@neurol.unizh.ch> wrote in message <ga3a72$sjl$1@fred.mathworks.com>...
> "s a":
> <SNIP breakpoint-blues...
>
> > I have a strange Matlab behavior
> > ...If i use the SAME code without any changes and just insert a break point on the error message the code run perfectly...
>
> can you produce a parsimonious snippet, which shows this behavior?
>
> us
In a nutshell
    AllPaths=cell2mat(ListScaleNodes{S,1}(SqrIndx));
       AllPaths=unique(AllPaths,'rows');
      for n=1:size(pTemp,1)
               z=pTemp(n,:);
               
               TP=sum((AllPaths(:,1:4)-z(ones(size(AllPaths,1),1),:)).^2,2);
               TTEIdx=TP<=1e-5;
               TTE=nnz(TTEIdx);
            
               if (TTE==0)
                    fprintf('PAth not found! please check code\n');
               
Thanks,
S

Subject: Matlab debugging question

From: Walter Roberson

Date: 8 Sep, 2008 14:27:14

Message: 9 of 11

s a wrote:

> I have a strange Matlab behavior,

> The problem is when the code is running I have many points not found but If i
> use the SAME code without any changes and just insert a break point on the
> error message the code run perfectly and locates all the points I need and returns
> correct results.

Interesting. I would suggest experimenting by telling Matlab to disable its
"Just In Time" acceleration. Unfortunately I do not recall the command for that
at the moment.

--
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end

Subject: Matlab debugging question

From: s a

Date: 8 Sep, 2008 17:53:02

Message: 10 of 11

Walter Roberson <roberson@hushmail.com> wrote in message <6Daxk.259331$gc5.168108@pd7urf2no>...
> s a wrote:
>
> > I have a strange Matlab behavior,
>
> > The problem is when the code is running I have many points not found but If i
> > use the SAME code without any changes and just insert a break point on the
> > error message the code run perfectly and locates all the points I need and returns
> > correct results.
>
> Interesting. I would suggest experimenting by telling Matlab to disable its
> "Just In Time" acceleration. Unfortunately I do not recall the command for that
> at the moment.
>
> --
> Q = quotation(rand);
> if isempty(Q); error('Quotation server filesystem problems')
> else sprintf('%s',Q), end
Well disabling the "Just In Time" acceleration seems to do the trick.

Subject: Matlab debugging question

From: Walter Roberson

Date: 8 Sep, 2008 18:20:05

Message: 11 of 11

s a wrote:

> Well disabling the "Just In Time" acceleration seems to do the trick.

Sounds like something that should be reported to Matlab support.
 


--
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com