1

I wrote some script called drawCurves.m to draw some curves. Then I called this script via publish function:

publish('drawCurves.m', 'outputDir', destPath, 'showCode', false)

Unfortunately, no any breakpoints set inside drawCurves trigger. If I call script directly by name, breakpoints do trigger.

Is it possible to fix somehow?

Adiel
  • 3,071
  • 15
  • 21
Dims
  • 47,675
  • 117
  • 331
  • 600
  • That only make sense that `publish` here acts like `live script`, that ignores graphic breakpoints. Try the programming breakpoint with `dbstop`, it's interesting to know if it works... – Adiel Jan 10 '18 at 08:48
  • From the docs, `publish` is used to "Generate view of MATLAB file in specified format", not for debugging (which is what breakpoints are for)... Why are you trying to debug your code and publish at the same time? – Wolfie Jan 10 '18 at 09:13
  • Why don't you use `pause()` for that, if your objective is making a script that stops until the user tells it to continue – Ander Biguri Jan 10 '18 at 11:35

1 Answers1

3

The publish command calls a private function evalmxdom to actually run the code in your file. You can find evalmxdom at $matlabroot%\toolbox\matlab\codetools\private\evalmxdom.m, where $matlabroot$ is your MATLAB installation directory.

If you read through it, you'll find a section at around line 60 where it stores the current breakpoints, turns them all off, and then sets things up so that the original breakpoints are restored when publishing is finished.

You'll notice that the code calls a subfunction safeDbclear that clears the breakpoints. Try commenting out the contents of that subfunction, and publishing again.

NB:

  1. I'm on R2017a: if you're on a different version and this file has changed between versions, the line numbers may be different.
  2. Be careful: you will be modifying files that are part of your MATLAB installation here. Take a backup of the file before you make a change to it.
  3. This may well mess up some aspects of publishing - it's turning off breakpoints for a reason.
Sam Roberts
  • 23,951
  • 1
  • 40
  • 64