Function variable -> cftool import data.

4 views (last 30 days)
Chris C
Chris C on 13 Jul 2016
Answered: Sean de Wolski on 20 Sep 2016
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 Comments
Chris C
Chris C on 13 Jul 2016
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. on 20 Sep 2016
Edited: Christiane Sch. on 20 Sep 2016
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.

Sign in to comment.

Answers (1)

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

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!