Passing variables in a GUI

Hi, I have a problem in a GUI: I have need of two function (fun1 and fun2) which can be activated or not (due to the activation of two check buttons). If both are activated, i need to pass some variables from fun1 to fun2.
Once it run (one or both functions) i should pass the results to another function (grafic_fun) which plot the final results.
The problem is that the others functions (fun2 and grafic_fun) don't read the variables (handles.var) that I have defined within the functions fun1 and fun2 ; the matlab's error: ?? Reference to non-existent field 'var1'.
The code are something like this:
function pushbutton_run_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if handles.check_fun1==1&&handles.check_fun2==1
fun1(hObject,handles)
fun2(hObject,handles)
grafic_fun(hObject,handles)
elseif handles.check_fun1==1&&handles.check_fun2==0
fun1(hObject,handles)
grafic_fun(hObject,handles)
else
fun2(hObject,handles)
grafic_fun(hObject,handles)
end
function fun1
...
handles.var1=...
handles.var2=...
guidata(hObject,handles)
function fun2
...
handles.var3=handles.var1+....
guidata(hObject,handles)
function grafic_fun(hObject,handles)
...
plot(x,handles.var)
guidata(hObject,handles)
thanks and sorry for my bad english!!

5 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 30 日
Matteo3 commented
Sorry, I have forget to write, the correct definition of functions is:
function fun1(hObject, handles)
...
handles.var1=...
handles.var2=...
guidata(hObject,handles)
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 30 日
And what is the problem?
Matteo3
Matteo3 2014 年 1 月 30 日
That in fun2(hObject, handles), the espression
handles.var3=handles.var1
where handles.var1 is defined in fun1(hObject, handles), return:
?? Reference to non-existent field 'var1'.
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 30 日
編集済み: Azzi Abdelmalek 2014 年 1 月 30 日
Maybe, in your filename_openingFcn you should initialize
handles.var1=....
Matteo3
Matteo3 2014 年 1 月 30 日
thanks!!

サインインしてコメントする。

回答 (2 件)

Amit
Amit 2014 年 1 月 30 日
編集済み: Amit 2014 年 1 月 30 日

0 投票

This is because fun1 and fun2 do not know the existence of handles inside that function.
You can try something like this:
function [var1 var2] = fun1
function var3 = fun2(var1,var)
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 30 日

0 投票

In your function arguments, add a variable handles. for example
function y=fcn1(a,b,handles)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

質問済み:

2014 年 1 月 30 日

コメント済み:

2014 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by