Function variable -> cftool import data.

3 次查看(过去 30 天)
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