0

Question: Is there a preferred way to debug functions in matlab?

If I all calculations in a script, then every variable is in the workspace and I can easily query them to find out what's not working right. However, if I use a function, then only my outputs are visible and I can't see what's going wrong. I understand there are ways of getting around this, but thusfar they seem to be more trouble than just making one, long ugly, script. So how do YOU debug functions in matlab? Is there a preferred/efficient way of doing this?

6
  • Did you even google.com/search?q=matlab+debug&ie=utf-8&oe=utf-8? :) Commented Oct 9, 2015 at 18:47
  • Uh yeah, thanks the suggestion though Commented Oct 9, 2015 at 19:29
  • I mean, is there anyway to get variables without using the debugger? Commented Oct 9, 2015 at 19:30
  • The preferred/efficient way is to use the debugger... Commented Oct 9, 2015 at 19:37
  • 1
    damn! i was hoping this wasn't the answer... thanks gang. Commented Oct 9, 2015 at 19:49

1 Answer 1

3

I always make sure to enable "Stop If Error" in the Breakpoints menu and if I want to debug a specific function I set a breakpoint at the first line in that function (or at the point of interest). Note that "clear all", which is common in the beginning of scripts deletes all break points. Use "clear variables" instead.

See MATLAB settings - stop if errors for more info on how to make the Stop If Error persist when you restart Matlab.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.