GUI, how to use previous loaded structure into next callback function?

2 views (last 30 days)
How to use the structure loaded into the next pushbutton_callback fuction? Once the push button is clicked a popup window appears where you can select the time fram you want to look at from the structure. The structure includes fields, where one field is called data and has multiple rows and columns. The 3rd pushbutton displays a list of the different variables in this field of the structure, and I have the same problem here. How is it possible to "attach" or "assign" this structure to the buttons and somehow be able to select fields and data from the structure?
% -
% --- 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') %,'Select One or More Files','MultiSelect', 'on')
fullFileName = fullfile(pathname, filename)
MyData= load(filename);
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)
handles = guidata(hObject);
% Below is a popup window where your desired time fram can be selected
prompt = {'Enter start time (format: 01-Jan-2019 00:00:00):','Enter end time: (format: 01-Jan-2019 00:00:00)','Enter the length of time window (in Hours):'};
dlgtitle = 'Input';
dims = [1 50];
definput = {'01-Jan-2019 00:00:00','01-Jan-2019 00:10:00','1'};
answer = inputdlg(prompt,dlgtitle,dims,definput)
guidata(hObject,handles)
%%
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
% Below is a list of variables from the data field of the structure
list = {'A','B','C','D','E','F'
'G','H','I','J'};
[indx,tf] = listdlg('ListString',list);
guidata(hObject,handles)

Accepted Answer

Adam Danz
Adam Danz on 18 Jul 2019
" How is it possible to "attach" or "assign" this structure to the buttons and somehow be able to select fields and data from the structure?"
It looks like you were on the right track.
% Assign the structure to GUI DATA
function pushbuttonx_Callback(hObject, eventdata, handles)
handles.yourStruct = yourStruct;
guidata(hObject, handles);
%Retreive the structure from GUI DATA
function pushbuttonz_Callback(hObject, eventdata, handles)
yourStruct = handles.yourStruct;
  4 Comments
Oda Gjerde
Oda Gjerde on 22 Jul 2019
Yes, that is somewhat what i meant. I found the column and row of the start and end time of the selected interval by using find(s.Time==starttime). And then used these columns and rows to find the data. The date and time are in the same field but the data is in a different field, and I wanted to use the data from the selected interval to plot a graph Time vs different columns of data.
Adam Danz
Adam Danz on 22 Jul 2019
In this case I would use logical indices where 1s (true) mark the datetime chosen. Then you can selected the data using the same logical index assuming there is a 1:1 correspondence between the data and the datetime vector.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!