How to save a workspace with fittypes that use anonymous functions?

조회 수: 1 (최근 30일)
Sophie
Sophie 2024년 3월 24일
답변: SACHIN KHANDELWAL 2024년 4월 16일
I am defining fittypes that refer to an anonymous functions. Afterwards I fit the model and saved the workspace. Here is a minimalistic example:
testfunc = @(params1, params2, x) params1*x + params2*x.^2;
testfittype = fittype(@(params1, params2, x) 2*testfunc(params1, params2, x));
x = [1;2;3];
y = [1;5;20];
[model, gof, output] = fit(x, y, testfittype);
Warning: Start point not provided, choosing random start point.
Now whenever I close matlab and load the saved workspace I get warnings that seem to stem from the anonymous function definition inside the fittype.
Warning: Could not find appropriate function on path loading function handle
My question is how can I get around those errors? I know that I could just avoid putting an anonyous function inside a fittype definition but since my real examples are quite long I would like to avoid that.
  댓글 수: 5
Sophie
Sophie 2024년 3월 24일
If I execute the save and load code in my local matlab I also do not get the warning. However if I close matlab and open it again, I do get the warning when importing the data from the previously saved workspace. Would you mind confirming that it works on your side when restarting matlab and then importing the previously saved workspace?
Matt J
Matt J 2024년 3월 24일
The same code I ran aboe works on my local computer as well.

댓글을 달려면 로그인하십시오.

답변 (1개)

SACHIN KHANDELWAL
SACHIN KHANDELWAL 2024년 4월 16일
It seems you're experiencing some difficulties while attempting to save a workspace that includes "fittype" function.
To help with this, I'd kindly suggest using MATLAB's "save" function to preserve your workspace in a '.MAT' file. Once saved, you can easily retrieve your workspace at any time by employing the 'load' function in MATLAB.
I tried it on my end, and it is working as expected.
Thanks!

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by