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.
If you want more about debugging, look at a recent MATLAB desktop blog post on the subject also.
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!
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?
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!
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
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
@Par,
Good catch. I think the intent was clear enough that I am not going to rerecord.
-Doug