Function variable -> cftool import data.

조회 수: 15 (최근 30일)
Chris C
Chris C 2016년 7월 13일
답변: Sean de Wolski 2016년 9월 20일
Dear Matlab Community,
Thanks for years of answering questions via google. I'm afraid I've come across the un-googleable though-
I'm desperate for help to get variables from function variable space into cftool for editing without exiting the function.
1) I've a function (called by button press from GUI) which makes a bunch of readings via a sensor for calibration.
2) I want to import these readings into cftool (curve fitting tool), so I can manually fit and save a fit function to apply later to other data (as final part of function).
But, cftool only takes import data from workspace variables... And no matter what I do, I cannot get the variables in the function variable space into the workspace and get cftool to see them. Example function below:
function blah=testgetvar(a,b,c)
global x; %attempt 3: does not work.
global y;
x=1:100;
y=x.*a+b.*rand(1,100)+c*ones(1,100);
%attempt 1: doesn't work
assignin('base','var1',x);
assignin('base','var2',y);
% attempt 2: also doesn't work.
save('testvar1.mat','x');
save('testvar2.mat','y');
load testvar1;
load testvar2;
cftool
pause; %for me to manually fit curve, delete outliers, etc...
%<resume and apply cftool's fit to process other data here>
blah=1;
Things I've tried:
- assignin doesn't save variables into workspace until function exits. I can't call assignin from inside another function. It doesn't work as a work-around.
-saving and loading variables. I think it gets loaded into variable space.
- declaring variables in function as global doesn't seem to work either.
Sincerely Thanks in advance,
-Chris
  댓글 수: 2
Chris C
Chris C 2016년 7월 13일
Still looking for a solution, but At least with a GUI, one work-around is to use
assignin('base','variable1',x);
assignin('base','variable2',y);
in one function, and call cftool in another function (as in, add an extra button for everything that is cftool and after).
Christiane Sch.
Christiane Sch. 2016년 9월 20일
편집: Christiane Sch. 2016년 9월 20일
Hello Chris,
I don't know if it helps you with your problem.
I also wanted to call the cftool within a function and give x and y values for the fit.
It worked for me giving the variables as parameters into the call, i.e. cftool(x,y). I'm not sure that's the solution for your problem, too, as you have variables within y.
Good luck.

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

답변 (1개)

Sean de Wolski
Sean de Wolski 2016년 9월 20일
function blah=testgetvar(a,b,c)
x=1:100;
y=x.*a+b.*rand(1,100)+c*ones(1,100);
cftool(x,y)
keyboard

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by