Passing parameters throughout nested functions

조회 수: 1 (최근 30일)
Salvatore
Salvatore 2014년 3월 17일
댓글: Salvatore 2014년 3월 17일
Hello I've some problems to handle some parameters that I've originally generated in a function which calls (trought callbacks) more functions whic use those parameters and update them. In the following an example of what I mean.
"Data" should be updated by callbacks @myinput and then @mygraph and return to the main function.
I don't know how to handle the outputs of callbacks.
Many thanks in advance for any suggestion.
Salvatore
*************************
function Data=Interface()
Data.a = ...;
Data.b = ...;
Data.c = [];
uicontrol(...,'Callback',{@myinput, Data});
...
uicontrol(...,'Callback',{@mygraph, Data});
function myinput(Data)
Data.c = ...;
Data.a.x = ...;
...
end
function mygraph(Data)
A = Data.a;
B = Data.a.x;
C = Data.b;
Data.d = ...;
end
end

답변 (1개)

Kevin Claytor
Kevin Claytor 2014년 3월 17일
편집: Kevin Claytor 2014년 3월 17일
Is this in a GUI? I'd have a look at guidata() and at get/setappdata, both of which help solve the problem of handling data in GUI's. Some examples;
function foobar(figure_handle)
figdata = guidata(figure_handle);
data = figdata.data;
% do stuff
% Store the data again
figdata.data = data;
guidata(figure_handle, figdata);
And for get/setappdata;
function foobar(figure_handle)
mydata = getappdata(some_handle,'data');
% do stuff
% Store the data again
setappdata(some_handle, 'data', mydata);
  댓글 수: 1
Salvatore
Salvatore 2014년 3월 17일
Hi Kevin,
while waiting for an answer I've found the guidata function.
This is the answer to my question.
Many thanks
Salvatore

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by