Highlights
Seguir


La encuesta está CERRADA

Encuesta

What is your main tool or approach for debugging MATLAB code?

Set breakpoints
60%
Run with "Pause On Errors"
11%
The dbstop() command
2%
Pause the code with keyboard()
3%
Get help from Matlab Community
16%
Other
7%
2506 votos

Michaela Maier
Michaela Maier el 27 de Jul. de 2022
i don't know why, but i often have problems that no amount of 'clear all' will solve (often involving MVMEvent/invokeListener) but restarting matlab will.
David Cazenave
David Cazenave el 16 de Jul. de 2022
I go to documentation and answers.
Sheridan McPheeters
Sheridan McPheeters el 21 de Jun. de 2022
Now that I know that "pause on error" exists, I'll probably use it instead of breakpoints... will have to look into these other options, as well. If they were around when I first started learning MATLAB in 2008 or so, I wasn't instructed on them. I guess that breakpoints are also a nearly universal debugging tool, so it's easy to get caught in the habit of using them (even though I code almost exclusively in MATLAB, these days).
Michael Van de Graaff
Michael Van de Graaff el 25 de Abr. de 2022
Learning about the keyboard command was life changing for me
Matt J
Matt J el 27 de Abr. de 2022
But why not dbstop, or inserted break points?
Michael Van de Graaff
Michael Van de Graaff el 21 de Mayo de 2022
I think i learned about keyboard before conditional dbstop. I just put problem code in try blocks and then keyboard in the catch block.
Lukas Öhlund
Lukas Öhlund el 20 de Abr. de 2022

disp('Got this far no29') works pretty well ;)

Joking aside, "Pause on Errors" has worked best for me - when it works. 9/10 times it does not trigger on an error for me. How do you guys get it to work?

Christian Stadelmann
Christian Stadelmann el 20 de Abr. de 2022

It only works if the error is not being caught by some try/catch block. To also pause on caught errors, follow these steps (Matlab 2016b): 1. in the "Editor" tab, open the menu below "Breakpoints" by pressing the arrow down 2. click "More Error and Warning Handling Options" 3. select tab "Try/Catch Errors" 4. select the second or third option

Matt J
Matt J el 13 de Abr. de 2022 (Editada a las el 13 de Abr. de 2022)

I wonder what the "Other" methods are that people are using. The score in that category is higher than I expected.

Alyona Buyukli
Alyona Buyukli el 6 de Jul. de 2022
a good old print-statement :D
Faouzi Rahmouni
Faouzi Rahmouni el 4 de Abr. de 2022

The best one is the live script.

DGM
DGM el 1 de Abr. de 2022

I have a simple 4-step approach that usually works.

  1. get so mad that steam comes out of my ears
  2. slam face on keyboard like a cartoon character
  3. roll around on the floor screaming obscenities
  4. troubleshoot the problem and fix it i guess

I hope that someone finds this helpful.

Michael Van de Graaff
Michael Van de Graaff el 27 de Jul. de 2022
huh..... that's a pretty good plan.
Mine is the same but i dont include step 4.
It's a bold strategy, let's see if it pays off!
Sheridan McPheeters
Sheridan McPheeters el 21 de Jun. de 2022
Someone had asked why there were so many "other" answers in the poll and was wondering what "other" debugging methods might be. Asked and answered!
Walter Roberson
Walter Roberson el 31 de Mzo. de 2022

dbstop if error can help me locate the place the code bombs, but working backwards from there to locate the cause of the error is mostly breakpoints... and fprintf.

Rik
Rik el 30 de Mzo. de 2022

Some older releases don't automatically open the file and move the cursor if you use keyboard, so I use the line below on such releases. It works without incident (even on GNU Octave), as long as I never cd.

ans=dbstack;dbstop('in',strrep(mfilename,'.m',''),'at',num2str(ans(1).line+1)),drawnow %#ok<NOANS>
dpb
dpb el 21 de Mayo de 2022
I mostly just "let 'er rip!" and see where it bombs, first, then set a breakpoint strategically there or somewhat before. That generally lets me find/correct logic errors within one or two iterations if I don't find I've made an egregious oversight or that makes me realize I should've used a far different approach from the beginning.
I'm the most frustrated with every new release the default behavior on breakpoint/dbstop is to put focus inside the function instead of the workspace...so one instinctively starts to type away and realize you're editing code instead of entering commands. So, have to go change preferences. Why the settings/preferences don't all migrate...
Michael Van de Graaff
Michael Van de Graaff el 21 de Mayo de 2022
this is why I love keyboard. the cursor is in the console

Etiquetas

Aún no se han introducido etiquetas.