I'm using NonLinearModelFit on a large set of data and which contains a nested Do-loop. I'd like to see all of the cases where there is an issue with the non-linear model fit, but after about five of these messages, further warnings are suppressed. Is there some way to make sure it doesn't suppress these messages after repeated warnings along the way?

z = NonlinearModelFit[trimspectra, a (x/x0)^(-b + c (Log[x/x0])), {a, b, c}, x];
  • 5
    From the docs on Message: Off[General::stop] makes the Wolfram Language not stop repeating messages. -- You might also be interested in Check. It can respond to messages even though the printing has stopped. -- Also perhaps of interest to you: mathematica.stackexchange.com/questions/20367/… – Michael E2 Mar 9 '16 at 20:25
  • Yes, Thank you Michael, Message: Off[General::stop] did the trick. When I get a message, is there a simple way to print out a variable to tell me where in the do-loop the issue occurred? Such as If[MessageList[-1]!={}, Print["Variable = ", variableOfInterest] ] ? – Tom Mozdzen Mar 11 '16 at 21:39
  • I just tried the If statement inside the loop. Outside the loop, it printed in a test case, but inside the loop, no printing. NonlinearModelFit::sszero: is my error warning. z = NonlinearModelFit[trimspectra, a (x/x0)^-b, {a, b}, x]; If[MessageList[-1] != {}, Print["LST = ", lst]]; – Tom Mozdzen Mar 11 '16 at 21:48
  • 1
    The Q I linked to has a good method. See my answer below. – Michael E2 Mar 11 '16 at 21:54
up vote 2 down vote accepted

From Szabolcs's answer to How to catch complete error message information, including the message text as it would be printed?:

report[m_] := If[NumericQ[i], Print[HoldForm[i] == i]];
Internal`AddHandler["Message", report];
Off[General::stop];

Do[
 1/Mod[i, 3],
 {i, 15}]

On[General::stop];
Internal`RemoveHandler["Message", report]

Mathematica graphics

One can also do the following if you know where the error might occur:

Do[
 Check[1/Mod[i, 3], Print[HoldForm[i] == i]],
 {i, 15}]

Mathematica graphics

  • Thanks again - the last section did it for me, but the 1st two sections are helpful in general for when I'd like to collect the messages. (-: – Tom Mozdzen Mar 11 '16 at 22:09
  • @Szabolcs Sorry! – Michael E2 Mar 11 '16 at 22:15
  • @MichaelE2 Don't worry about it, I know the spelling looks very strange :-) – Szabolcs Mar 13 '16 at 10:16

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.