Passing two subfunction variables in GUI to another function

1 回表示 (過去 30 日間)
Melissa
Melissa 2012 年 9 月 11 日
Good Afternoon All,
I have been searching matlab documentation and forums for a way to properly pass data from a subfunction to another function in a GUI. I have only found examples for one variable in a subfunction and I am not sure if the handles will work for two considering every attemp made the way I defined the handles only exist within the subfunction.
% --- Executes on button press in Bore_Profile_Generate_Pushbutton.
function Bore_Profile_Generate_Pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Bore_Profile_Generate_Pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Do simple equations and produce:
%Output results
angles = (prof(:,1))';
radius = (prof(:,2))';
%Then I try to use handles
handles.radius=radius;
handles.angles=angles;
Now I try to place it into a different function and fails.
% --- Executes on button press in Results_Analysis_Pushbutton.
function Results_Analysis_Pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Results_Analysis_Pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Running fft_coeff.m to obtain the Fourier Coefficients of Profile
%Radius and Angles are obtained from Bore_Profile_Generate_Pushbutton and
%N_terms are obtained from Results_Coefficients_Edit
radius = str2num(get(handles.radius));
angles = str2num(get(handles.angles));
Note that radius and angles are a 1 by n matrix.

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 9 月 11 日
You'll have to store the new handles structure at the end of the pushbutton callback using:
guidata(handles.figure1,handles);
Where 'figure1' is the tag of your figure, whatever that may be.
  10 件のコメント
Melissa
Melissa 2012 年 9 月 11 日
OMG it worked!!!!!!!!!!!!!!!
Thank you so much for your patience and time in assisting me.
Sean de Wolski
Sean de Wolski 2012 年 9 月 11 日
you're welcome!

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

その他の回答 (1 件)

Matt Fig
Matt Fig 2012 年 9 月 11 日
You add to handles, but then do not save handles. See the help for GUIDATA.
  2 件のコメント
Melissa
Melissa 2012 年 9 月 11 日
Thank you so much for the response. I referenced teh GUIdata and typed in the following but still received an error.
%Output results
angles = (prof(:,1))';
radius = (prof(:,2))';
%Declaring output results to be used for Distortion Results
handles.radius=radius;
handles.angles=angles;
%Saving Handles to be used.
guidata(handles.Bore_Distortion_Calculator,handles)
Matt Fig
Matt Fig 2012 年 9 月 11 日
編集済み: Matt Fig 2012 年 9 月 11 日
Use this instead:
guidata(gcbf,handles); % No need to mess around with tags...
And if you still receive an error, show the error message!

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by