Doug’s MATLAB Video Tutorials

November 20th, 2008

Video tutorial: Debugging a logical indexing problem

I love getting well formed question and challenges from fellow MATLAB users. This week I got one that works very well as a video. The problem was trying to index into a vector with a vector of ones and zeros. While this vector was all ones and zeros, it was still considered a double precision variable. I use DBSTOP to help figure out this situation. Because I was debugging this live, I made some unscripted errors that made this video a good capturing of the real confusion that comes when debugging and how to overcome those challenges.
MATLAB Central Files Icon If you want more about debugging, look at a recent MATLAB desktop blog post on the subject also.

4 Responses to “Video tutorial: Debugging a logical indexing problem”

  1. Par replied on :

    Nice video Doug! Learnt about dbstop.

    Just wanted to bring your attention to this: At about 2 minutes 20 seconds of the video, you do a “whos” and say “B is a double… that’s no good…”. I think you meant C there instead of B. Although this is quite obvious, and people should understand without any ambiguity, I thought I will let you know anyway, in case you wanted to correct that!

    Thanks!

  2. Petr Pošík replied on :

    Hi Doug.

    I love these short videos. Sometimes they remind me of something that I had known sometime in the past, but I forgot it then… :-)

    I think it is worth mentioning that it is not actually needed to change those C = 1 or C = 0 assignemnts to C = true and C = false, although it gives a nice idea of what a logical vector is. It is sufficient to call B(logical(C)) instead of B(C). The ‘logical’ function takes the double vector C full of 0s and 1s and creates a logical vector full of falses and trues. Am I right?

    Petr

  3. dhull replied on :

    Petr,

    Yes, you could indeed simply convert the vector at the end with logical. But if it is going to be a logical vector, night as well create it as such.

    Mostly a style issue, but if I am going to use it ten times as a logical, I might as well just create it as a logical.

    -Doug

  4. dhull replied on :

    @Par,

    Good catch. I think the intent was clear enough that I am not going to rerecord.

    -Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.