Help with sharing data between multiple GUI
Show older comments
I have a GUI (made with GUIDE) that has various elements inside it, including some editable text boxes for inputting data, and some pushbuttons for executing processing on that data. One of those pushbuttons is set to do three things:
1. Process some of the data
2. Export the processed data to an .xls file
3. Open a second GUI (also created wit GUIDE)
In this second GUI, there are two pushbuttons: "Open File" and "Close". The "Close" pushbutton simply closes this second GUI. The "Open File" pushbutton is where I am having trouble. This pushbutton is supposed to open the newly created file in Excel (using winopen), but for the life of me I cannot get it to work. Through the processing that occurs in the first GUI, I have the filepath to this file stored as a string. But I cannot seem to get this string variable passed over to the second GUI so that it can be used with winopen to open the file upon clicking the pushbutton.
Based on what I'm reading online, it seems like I need to be using some combination of setappdata/getappdata, or perhaps some use of guidata. But honestly, the documentation available on how to share data among callbacks might as well be in a foreign language as far as I'm concerned, because reading it provides me absolutely no insight into how to go about applying it to my situation.
Can anybody help me out with this? Below is some of my code.
A snippet from the first GUI:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname]=uigetfile('*.mat'); % get filepath
handles.data = load([pathname,filename]); % load data from filepath
handles.file_name = ([handles.data.name '_export.xls']); % create export file name
guidata(hObject,handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
process_data % run process_data.m to process the data
export_data % run export_data.m to export the data to an .xls file
post_export % run post_export.m to allow file selection after export
So the above code is all inside the first GUI. the script "post_export.m" creates the second GUI, which is where I'm having my problems. Below is a snippet of code from that:
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
winopen(handles.file_name)
Answers (0)
Categories
Find more on Interactive Control and Callbacks 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!