Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Jeff
Jeff 2017년 11월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
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?

답변 (1개)

Mukul Rao
Mukul Rao 2017년 12월 4일
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
Jeff
Jeff 2017년 12월 5일
I already found a workaround using the global command.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by