Thread Subject: Strange errors

Subject: Strange errors

From: Matthew Sullivan

Date: 26 Oct, 2007 14:46:32

Message: 1 of 13

I've been running in to a strange MATLAB script problem that
I don't quite understand. The specific error I get is
"Subscript indices must either be real positive integers or
logicals." The indices I use are real positive integers,
though. When I copy and past the offending commend in to the
MATLAB command line, it executes without issue.

The most frustrating thing is that the errors are not
repeatable. If I clear memory and rerun, it sometimes will
work. Other times, it seems to stop elsewhere in the
script, or at another point in the loop. I've only recently
run in to this issue, as well. I can sometimes get the
error running older code that I hadn't run in a long time
and had no problems with when I ran it months ago.

I assume there's something wrong with my computer or the
script I'm running. As it appears somewhat randomly I am at
a loss for fixing it. For completeness, here is my most
recent error message:

?? Subscript indices must either be real positive integers
or logicals.

Error in ==> track at 502
                ym = y(ymat(1:lenxn,1:lenxm));

Error in ==> deflect_stitch_2 at 103
            trt = track(xyt', trackdist, params);

lenxn = trackdist = 25



Subject: Strange errors

From: Titus

Date: 26 Oct, 2007 14:57:58

Message: 2 of 13


"Matthew Sullivan" <nospam@nospam.no> schrieb im Newsbeitrag
news:ffsuk8$331$1@fred.mathworks.com...
> I've been running in to a strange MATLAB script problem that
> I don't quite understand. The specific error I get is
> "Subscript indices must either be real positive integers or
> logicals." The indices I use are real positive integers,
> though. When I copy and past the offending commend in to the
> MATLAB command line, it executes without issue.
>
> The most frustrating thing is that the errors are not
> repeatable. If I clear memory and rerun, it sometimes will
> work. Other times, it seems to stop elsewhere in the
> script, or at another point in the loop. I've only recently
> run in to this issue, as well. I can sometimes get the
> error running older code that I hadn't run in a long time
> and had no problems with when I ran it months ago.
>
> I assume there's something wrong with my computer or the
> script I'm running. As it appears somewhat randomly I am at
> a loss for fixing it. For completeness, here is my most
> recent error message:
>
> ?? Subscript indices must either be real positive integers
> or logicals.
>
> Error in ==> track at 502
> ym = y(ymat(1:lenxn,1:lenxm));
>
> Error in ==> deflect_stitch_2 at 103
> trt = track(xyt', trackdist, params);
>
> lenxn = trackdist = 25
>
>
>

Hi Matthew,
are you sure, that ymat has only integer values? Sometimes it
might happen that they look like integers but they don't. You can
try by computing
ymat2 = ymat - round(ymat);
before line 502 and see, if ymat2 is really zero by
ymatIsInteger = ~any(ymat(:))

If they should be integers but are not (due to roundoff),
use round(ymat) instead of ymat.

Titus


Subject: Strange errors

From: John D'Errico

Date: 26 Oct, 2007 15:06:38

Message: 3 of 13

"Matthew Sullivan" <nospam@nospam.no> wrote in message <ffsuk8$331
$1@fred.mathworks.com>...
> I've been running in to a strange MATLAB script problem that
> I don't quite understand. The specific error I get is
> "Subscript indices must either be real positive integers or
> logicals." The indices I use are real positive integers,
> though. When I copy and past the offending commend in to the
> MATLAB command line, it executes without issue.
>
> The most frustrating thing is that the errors are not
> repeatable. If I clear memory and rerun, it sometimes will
> work. Other times, it seems to stop elsewhere in the
> script, or at another point in the loop. I've only recently
> run in to this issue, as well. I can sometimes get the
> error running older code that I hadn't run in a long time
> and had no problems with when I ran it months ago.
>
> I assume there's something wrong with my computer or the
> script I'm running. As it appears somewhat randomly I am at
> a loss for fixing it. For completeness, here is my most
> recent error message:
>
> ?? Subscript indices must either be real positive integers
> or logicals.
>
> Error in ==> track at 502
> ym = y(ymat(1:lenxn,1:lenxm));
>
> Error in ==> deflect_stitch_2 at 103
> trt = track(xyt', trackdist, params);
>
> lenxn = trackdist = 25

The problem is not with lenxn and indexing into
ymat.

The problem is that ymat apparently does not
always contain pure integers.

So your indexing into y is the problem.

John

Subject: Strange errors

From: ImageAnalyst

Date: 26 Oct, 2007 15:39:22

Message: 4 of 13

On Oct 26, 10:46 am, "Matthew Sullivan" <nos...@nospam.no> wrote:
> I've been running in to a strange MATLAB script problem that
> I don't quite understand. The specific error I get is
> "Subscript indices must either be real positive integers or
> logicals." The indices I use are real positive integers,
> though. When I copy and past the offending commend in to the
> MATLAB command line, it executes without issue.
>
> The most frustrating thing is that the errors are not
> repeatable. If I clear memory and rerun, it sometimes will
> work. Other times, it seems to stop elsewhere in the
> script, or at another point in the loop. I've only recently
> run in to this issue, as well. I can sometimes get the
> error running older code that I hadn't run in a long time
> and had no problems with when I ran it months ago.
>
> I assume there's something wrong with my computer or the
> script I'm running. As it appears somewhat randomly I am at
> a loss for fixing it. For completeness, here is my most
> recent error message:
>
> ?? Subscript indices must either be real positive integers
> or logicals.
>
> Error in ==> track at 502
> ym = y(ymat(1:lenxn,1:lenxm));
>
> Error in ==> deflect_stitch_2 at 103
> trt = track(xyt', trackdist, params);
>
> lenxn = trackdist = 25

============================================================
Put a breakpoint there and check the workspace to see if it calls ymat
an array of integers or doubles.
Also, you can do class(ymat) in the command window at that breakpoint
to see what MATLAB thinks it really is.
It will report back the data type it considers it: some flavor or
floating point, or some flavor of integer.
Good luck,
ImageAnalyst

Subject: Strange errors

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 26 Oct, 2007 17:05:01

Message: 5 of 13

In article <ffsuk8$331$1@fred.mathworks.com>,
Matthew Sullivan <nospam@nospam.no> wrote:
>I've been running in to a strange MATLAB script problem that
>I don't quite understand. The specific error I get is
>"Subscript indices must either be real positive integers or
>logicals."

You can encounter that problem if you think you are calling
a function, but you have accidently introduced a variable with
the same name as the function so that it is trying to index
the variable with function arguments.
--
   So you found your solution
   What will be your last contribution?
   -- Supertramp (Fool's Overture)

Subject: Strange errors

From: Matthew Sullivan

Date: 26 Oct, 2007 20:10:56

Message: 6 of 13

 ImageAnalyst <imageanalyst@mailinator.com> wrote in message
<1193413162.578228.104670@o3g2000hsb.googlegroups.com>...
> On Oct 26, 10:46 am, "Matthew Sullivan" <nos...@nospam.no>
wrote:
> > I've been running in to a strange MATLAB script problem that
> > I don't quite understand. The specific error I get is
> > "Subscript indices must either be real positive integers or
> > logicals." The indices I use are real positive integers,
> > though. When I copy and past the offending commend in to the
> > MATLAB command line, it executes without issue.
> >
> > The most frustrating thing is that the errors are not
> > repeatable. If I clear memory and rerun, it sometimes will
> > work. Other times, it seems to stop elsewhere in the
> > script, or at another point in the loop. I've only recently
> > run in to this issue, as well. I can sometimes get the
> > error running older code that I hadn't run in a long time
> > and had no problems with when I ran it months ago.
> >
> > I assume there's something wrong with my computer or the
> > script I'm running. As it appears somewhat randomly I am at
> > a loss for fixing it. For completeness, here is my most
> > recent error message:
> >
> > ?? Subscript indices must either be real positive integers
> > or logicals.
> >
> > Error in ==> track at 502
> > ym = y(ymat(1:lenxn,1:lenxm));
> >
> > Error in ==> deflect_stitch_2 at 103
> > trt = track(xyt', trackdist, params);
> >
> > lenxn = trackdist = 25
>
> ============================================================
> Put a breakpoint there and check the workspace to see if
it calls ymat
> an array of integers or doubles.
> Also, you can do class(ymat) in the command window at that
breakpoint
> to see what MATLAB thinks it really is.
> It will report back the data type it considers it: some
flavor or
> floating point, or some flavor of integer.
> Good luck,
> ImageAnalyst
>


Thanks for the suggestions, but I'm afraid I didn't do a
good job of detailing my problem. I am running data
analysis on a number of files in a loop. The command that
crashes is always a pair like this:

negative = find(ydata < 0);
plot(xdata(negative), -ydata(negative), '.');

for most of the iterations through the loop, it works fine,
but at some point it gives the above message. The confusing
things to me are:

1) it doesn't always stop at the same place in the loop
2) it doesn't always happen, sometimes it works, sometimes
it doesn't
3) if I look at the array negative, it is filled with
positive integers. max(negative-floor(negative)) = 0.
4) if I simply copy the failed command from the command
window the command works without fail.

My real question is: why does the same exact code not
always produce the same exact results?

Subject: Strange errors

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 26 Oct, 2007 20:26:45

Message: 7 of 13

In article <ffthkg$dd$1@fred.mathworks.com>,
Matthew Sullivan <nospam@nospam.no> wrote:

>My real question is: why does the same exact code not
>always produce the same exact results?

Turn off JIT (Just In Time Compiling) and you may see more
consistant results.

--
   "History is a pile of debris" -- Laurie Anderson

Subject: Strange errors

From: Matthew Sullivan

Date: 31 Oct, 2007 17:32:14

Message: 8 of 13

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fftii5$2ns$1@canopus.cc.umanitoba.ca>...
> In article <ffthkg$dd$1@fred.mathworks.com>,
> Matthew Sullivan <nospam@nospam.no> wrote:
>
> >My real question is: why does the same exact code not
> >always produce the same exact results?
>
> Turn off JIT (Just In Time Compiling) and you may see more
> consistant results.
>
> --
> "History is a pile of debris" --
Laurie Anderson

That sounds like a good idea. I can't figure out how to
turn off JIT, though. How do I do that?
Thanks

Subject: Strange errors

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 31 Oct, 2007 18:29:02

Message: 9 of 13

In article <fgae6u$p07$1@fred.mathworks.com>,
Matthew Sullivan <nospam@nospam.no> wrote:
>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
>message <fftii5$2ns$1@canopus.cc.umanitoba.ca>...

>> Turn off JIT (Just In Time Compiling) and you may see more
>> consistant results.

>That sounds like a good idea. I can't figure out how to
>turn off JIT, though. How do I do that?

feature('JIT',0)

To turn it back on,

feature('JIT',1)

--
  "I will speculate that [...] applications [...] could actually see a
  performance boost for most users by going dual-core [...] because it
  is running the adware and spyware that [...] are otherwise slowing
  down the single CPU that user has today" -- Herb Sutter

Subject: Strange errors

From: ImageAnalyst

Date: 1 Nov, 2007 02:32:43

Message: 10 of 13

On Oct 26, 4:10 pm, "Matthew Sullivan" <nos...@nospam.no> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message
>
> <1193413162.578228.104...@o3g2000hsb.googlegroups.com>...
>
>
>
>
>
> > On Oct 26, 10:46 am, "Matthew Sullivan" <nos...@nospam.no>
> wrote:
> > > I've been running in to a strange MATLAB script problem that
> > > I don't quite understand. The specific error I get is
> > > "Subscript indices must either be real positive integers or
> > > logicals." The indices I use are real positive integers,
> > > though. When I copy and past the offending commend in to the
> > > MATLAB command line, it executes without issue.
>
> > > The most frustrating thing is that the errors are not
> > > repeatable. If I clear memory and rerun, it sometimes will
> > > work. Other times, it seems to stop elsewhere in the
> > > script, or at another point in the loop. I've only recently
> > > run in to this issue, as well. I can sometimes get the
> > > error running older code that I hadn't run in a long time
> > > and had no problems with when I ran it months ago.
>
> > > I assume there's something wrong with my computer or the
> > > script I'm running. As it appears somewhat randomly I am at
> > > a loss for fixing it. For completeness, here is my most
> > > recent error message:
>
> > > ?? Subscript indices must either be real positive integers
> > > or logicals.
>
> > > Error in ==> track at 502
> > > ym = y(ymat(1:lenxn,1:lenxm));
>
> > > Error in ==> deflect_stitch_2 at 103
> > > trt = track(xyt', trackdist, params);
>
> > > lenxn = trackdist = 25
>
> > ============================================================
> > Put a breakpoint there and check the workspace to see if
> it calls ymat
> > an array of integers or doubles.
> > Also, you can do class(ymat) in the command window at that
> breakpoint
> > to see what MATLAB thinks it really is.
> > It will report back the data type it considers it: some
> flavor or
> > floating point, or some flavor of integer.
> > Good luck,
> > ImageAnalyst
>
> Thanks for the suggestions, but I'm afraid I didn't do a
> good job of detailing my problem. I am running data
> analysis on a number of files in a loop. The command that
> crashes is always a pair like this:
>
> negative = find(ydata < 0);
> plot(xdata(negative), -ydata(negative), '.');
>
> for most of the iterations through the loop, it works fine,
> but at some point it gives the above message. The confusing
> things to me are:
>
> 1) it doesn't always stop at the same place in the loop
> 2) it doesn't always happen, sometimes it works, sometimes
> it doesn't
> 3) if I look at the array negative, it is filled with
> positive integers. max(negative-floor(negative)) = 0.
> 4) if I simply copy the failed command from the command
> window the command works without fail.
>
> My real question is: why does the same exact code not
> always produce the same exact results?- Hide quoted text -
>
> - Show quoted text -

===========================================
Matthew:
Are you 100% sure that negative is NEVER null? Does it still crash if
you do something like:
negative = find(ydata < 0);
if ~isempty(negative)
    plot(xdata(negative), -ydata(negative), '.');
end
Regards,
ImageAnalyst

Subject: Strange errors

From: Matthew Sullivan

Date: 2 Nov, 2007 00:33:17

Message: 11 of 13

 ImageAnalyst <imageanalyst@mailinator.com> wrote in message
<1193884363.080919.312120@22g2000hsm.googlegroups.com>...
> On Oct 26, 4:10 pm, "Matthew Sullivan" <nos...@nospam.no>
wrote:
> > ImageAnalyst <imageanal...@mailinator.com> wrote in message
> >
> > <1193413162.578228.104...@o3g2000hsb.googlegroups.com>...
> >
> >
> >
> >
> >
> > > On Oct 26, 10:46 am, "Matthew Sullivan" <nos...@nospam.no>
> > wrote:
> > > > I've been running in to a strange MATLAB script
problem that
> > > > I don't quite understand. The specific error I get is
> > > > "Subscript indices must either be real positive
integers or
> > > > logicals." The indices I use are real positive
integers,
> > > > though. When I copy and past the offending commend
in to the
> > > > MATLAB command line, it executes without issue.
> >
> > > > The most frustrating thing is that the errors are not
> > > > repeatable. If I clear memory and rerun, it
sometimes will
> > > > work. Other times, it seems to stop elsewhere in the
> > > > script, or at another point in the loop. I've only
recently
> > > > run in to this issue, as well. I can sometimes get the
> > > > error running older code that I hadn't run in a long
time
> > > > and had no problems with when I ran it months ago.
> >
> > > > I assume there's something wrong with my computer or the
> > > > script I'm running. As it appears somewhat randomly
I am at
> > > > a loss for fixing it. For completeness, here is my most
> > > > recent error message:
> >
> > > > ?? Subscript indices must either be real positive
integers
> > > > or logicals.
> >
> > > > Error in ==> track at 502
> > > > ym = y(ymat(1:lenxn,1:lenxm));
> >
> > > > Error in ==> deflect_stitch_2 at 103
> > > > trt = track(xyt', trackdist, params);
> >
> > > > lenxn = trackdist = 25
> >
> > >
============================================================
> > > Put a breakpoint there and check the workspace to see if
> > it calls ymat
> > > an array of integers or doubles.
> > > Also, you can do class(ymat) in the command window at that
> > breakpoint
> > > to see what MATLAB thinks it really is.
> > > It will report back the data type it considers it: some
> > flavor or
> > > floating point, or some flavor of integer.
> > > Good luck,
> > > ImageAnalyst
> >
> > Thanks for the suggestions, but I'm afraid I didn't do a
> > good job of detailing my problem. I am running data
> > analysis on a number of files in a loop. The command that
> > crashes is always a pair like this:
> >
> > negative = find(ydata < 0);
> > plot(xdata(negative), -ydata(negative), '.');
> >
> > for most of the iterations through the loop, it works fine,
> > but at some point it gives the above message. The confusing
> > things to me are:
> >
> > 1) it doesn't always stop at the same place in the loop
> > 2) it doesn't always happen, sometimes it works, sometimes
> > it doesn't
> > 3) if I look at the array negative, it is filled with
> > positive integers. max(negative-floor(negative)) = 0.
> > 4) if I simply copy the failed command from the command
> > window the command works without fail.
> >
> > My real question is: why does the same exact code not
> > always produce the same exact results?- Hide quoted text -
> >
> > - Show quoted text -
>
> ===========================================
> Matthew:
> Are you 100% sure that negative is NEVER null? Does it
still crash if
> you do something like:
> negative = find(ydata < 0);
> if ~isempty(negative)
> plot(xdata(negative), -ydata(negative), '.');
> end
> Regards,
> ImageAnalyst
>

I am 100% sure that negative is never null. When I look at
it, it is always a list of positive numbers. Furthermore,
when I just cut and past the last command it works without
problem.

I turned JIT off and I still get the randomly get these
errors. It has become so bad that I can't run scripts for >
20 files without always getting these errors.

Subject: Strange errors

From: Steven Lord

Date: 2 Nov, 2007 03:10:24

Message: 12 of 13


"Matthew Sullivan" <nospam@nospam.no> wrote in message
news:fgdr8d$me2$1@fred.mathworks.com...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> <1193884363.080919.312120@22g2000hsm.googlegroups.com>...

*snip*

> I am 100% sure that negative is never null. When I look at
> it, it is always a list of positive numbers. Furthermore,
> when I just cut and past the last command it works without
> problem.
>
> I turned JIT off and I still get the randomly get these
> errors. It has become so bad that I can't run scripts for >
> 20 files without always getting these errors.

Type "dbstop if error" without the quotes at the prompt, then run your code.
When you receive an error, you'll enter debug mode (the K>> prompt). From
there, you can see the line where the error is thrown and examine the exact
contents of the variables as they exist at the time that line is executed.
Double-check that all the variables you use as indices on that line contain
positive integers or logicals. Once you've finished your investigation, use
"dbquit" to exit debug mode and "dbclear all" to remove the condition that
caused you to enter debug mode when you received an error.

--
Steve Lord
slord@mathworks.com


Subject: Strange errors

From: Matthew Sullivan

Date: 3 Nov, 2007 22:03:07

Message: 13 of 13

"Steven Lord" <slord@mathworks.com> wrote in message
<fge4f0$126$1@fred.mathworks.com>...
>
> "Matthew Sullivan" <nospam@nospam.no> wrote in message
> news:fgdr8d$me2$1@fred.mathworks.com...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> > <1193884363.080919.312120@22g2000hsm.googlegroups.com>...
>
> *snip*
>
> > I am 100% sure that negative is never null. When I look at
> > it, it is always a list of positive numbers. Furthermore,
> > when I just cut and past the last command it works without
> > problem.
> >
> > I turned JIT off and I still get the randomly get these
> > errors. It has become so bad that I can't run scripts for >
> > 20 files without always getting these errors.
>
> Type "dbstop if error" without the quotes at the prompt,
then run your code.
> When you receive an error, you'll enter debug mode (the
K>> prompt). From
> there, you can see the line where the error is thrown and
examine the exact
> contents of the variables as they exist at the time that
line is executed.
> Double-check that all the variables you use as indices on
that line contain
> positive integers or logicals. Once you've finished your
investigation, use
> "dbquit" to exit debug mode and "dbclear all" to remove
the condition that
> caused you to enter debug mode when you received an error.
>
> --
> Steve Lord
> slord@mathworks.com
>
>

That was a useful tip, but again in debug mode everything
checks out (all positive integers). Running the command
that sent me to debug mode in debug mode works fine. I'm
still at a loss for what could be going on.

As a possible workaround, is there an equivalent to the IDL
command (I'm really showing my roots) .continue? That
wouldn't solve the root problem, but it stop it from
annoying me?

Thanks again,
Matt

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
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com