Function variable -> cftool import data.

4 ビュー (過去 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 Center および File ExchangeGet 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