Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Why are the results to the fit command getting cleared from the workspace?

1 vue (au cours des 30 derniers jours)
Jeff
Jeff le 30 Nov 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have attached 2 m-files. The 1st one calls on the 2nd one to generate a Fourier series curve fit. When I run it it terminates with the following error:
Reference to non-existent field 'R2'.
Error in FriedlanderFourierSeries2 (line 30) fitstats=[gof.sse gof.R2 gof.adjustedR2 gof.stdError];
It appears that the 2 workspace variables fitresult & gof get cleared out & I do not understand why. I figured this out by setting a breakpoint on line 30 & 33 of FriedlanderFourierSeries2.m. Both variables are visible in the workspace & when I continue they disappear. How do I hold onto those 2 variables?

Réponses (1)

Mukul Rao
Mukul Rao le 4 Déc 2017
Hi Jeff, the function "FriedlanderFourierSeries2" does not run to completion because of the error. Therefore, it does not return the output and clears variables in its scope, which includes "fitresult" and "gof".
The cause of the error is the expression "gof.R2", "R2" is not a valid field in "gof". You can either check if "R2" or another string is a valid field of "gof" using the isfield function. You can also use a try-catch statement around the "fitstats = ... " command.
A workaround, that you can consider, but which I would not strongly recommend is to use the assignin command right after you compute the fit and push these variables to the base workspace.
  1 commentaire
Jeff
Jeff le 5 Déc 2017
I already found a workaround using the global command.

Cette question est clôturée.

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by