Search code examples
matlabbreakpoints

How to check correctness of user written code in Matlab


I have a user written Matlab code which consists of multiple files. I read files one by one. If I need to check the correctness of a single file which implements a function, call it Func, then how to I check the specific file for errors? How do I apply break points so that I can see what the function is doing, because the function as defined in the file consists of variables, while I need to check part of the function using specific values.


Solution

  • I believe you are asking how to work with breakpoints.

    The easiest way to do this, is to click just left of your code. A red dot will appear to indicate that you set a breakpoint. I found an example image:

    enter image description here

    If your code reaches the breakpoint, it will stop there and you can evaluate all variables that exist at the time (most even with mouseover), as well as update them to represent the situation that you are interested in.


    If you want to evaluate multiple lines, you can stop before the relevant section (by putting a breakpoint there) and then hit f10 to evaluate a line. Make sure to check the documentation for more options.