Search code examples
matlabdebuggingimage-processinguser-input

While debugging with an input from the keyboard, I want to able to skip the execution of a few lines of code in MATLAB


Currently I have this excerpt of code I am trying to debug:

if (white_flag == 1)
    keyboard;
    imshow(rl_img);
    N = N+1; 
    times(times_index,1) = index; 
    while(white_flag == 1)
        imshow(rl_img);
        index = index+1; 

        %%% If statement for when the loop has run out
        if (index >= frames)
            break
        end

        %%% Initial Image Pre-Processing
        rl_img = ones(mod_height,width);
        pre_rl_img = medfilt2(vreader.read(index));
        for i = 1:mod_height
            for j = 1:width
                rl_img(i,j) = pre_rl_img(i,j); 
            end
        end

        white_flag = detect_white( rl_img, white_flag );
    end
    times(times_index,2) = index;
    times_index = times_index+1; 
else 
    index = index+ 1;
end

Now, as you can see, the debug keyboard input call keybaord is on the second line. While this allows me to efficiently see each step of the execution of my program, I do not understand how to skip over the part below:

        for i = 1:mod_height
            for j = 1:width
                rl_img(i,j) = pre_rl_img(i,j); 
            end
        end

This is a rather sizable picture(rl_img), so waiting for keyboard input while I scrawl through the code manually wastes a lot of time. Can someone please tell me how to skip the user input execution of these lines of code while I debug the program?

Please do not hesitate to ask me any questions that can clarify this problem. Thank you for all your answers!


Solution

  • The answer is quite straightforward:

    1. you set a breakpoint after the lengthy loop,

    2. when you decide to run automatically all the rest of the loop up to the breakpoint you just set, press [F5] (Continue).

    This assumes that you debug your code in the normal MATLAB IDE.