Highlights
팔로우


설문 종료

설문

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

Michaela Maier
Michaela Maier 2022년 7월 27일
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 2022년 7월 16일
I go to documentation and answers.
Sheridan McPheeters
Sheridan McPheeters 2022년 6월 21일
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 2022년 4월 25일
Learning about the keyboard command was life changing for me
Matt J
Matt J 2022년 4월 27일
But why not dbstop, or inserted break points?
Michael Van de Graaff
Michael Van de Graaff 2022년 5월 21일
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 2022년 4월 20일

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 2022년 4월 20일

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 2022년 4월 13일 (2022년 4월 13일에 수정됨)

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 2022년 7월 6일
a good old print-statement :D
Faouzi Rahmouni
Faouzi Rahmouni 2022년 4월 4일

The best one is the live script.

DGM
DGM 2022년 4월 1일

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 2022년 7월 27일
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 2022년 6월 21일
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 2022년 3월 31일

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 2022년 3월 30일

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 2022년 5월 21일
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 2022년 5월 21일
this is why I love keyboard. the cursor is in the console

태그

아직 태그를 입력하지 않았습니다.