I want to print the messages or warning message tags for NonlinearModelFit when batch fitting data. For example, I will import and fit my data with something like

       MyData = Import[DataSetList[[i]]];
           MyFit = NonlinearModelFit[MyData, MyFitFunction[a, b, c, x], {a, b, c}, x];
               MyFitMessageTags = (* ??? *);

       {i, MyFit, MyFitMessageTags},
       {i, 1, NumberOfDatasets}

The idea being that I can easily filter out fit results which have a message or specific message tag. I'm really struggling to find what I want. I've tried Messages[NonlinearModelFit] as I read this should output the messages associated to NonlinearModelFit from the previous session, but I don't see any change in the messages at all -- possibly because it is inside a table so that only counts as one session?I've also tried EvaluationData, but again I don't get what I expect here either.

Check could be an option but it seems that if you get any message then you don't get the output from the function. This is undesirable as sometimes Mathematica will issue a warning, even though the output is good. For example if the function has decided a better method should be used and switches from the default.

This should be very easy, and it probably is but I'm looking in the wrong place, but so far I am struggling!


1 Answer 1


Okay, one very roundabout way could be to encapsulate the fit in a Check and check for a null:

   MyFitCheck = 
          NonlinearModelFit[MyData, MyFitFunction[a, b, c, x], {a, b, c}, x];,
          "FIT WARNING"
   FitWarningTag = If[MyFitCheck == Null, "GOOD FIT -- NO WARNING", "FIT WARNING"]; 

It works, but it would be better to output the specific tag.


Your Answer

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

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