MATLAB Answers

0

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

Asked by Oda Gjerde on 18 Jul 2019
Latest activity Commented on by Adam Danz
on 22 Jul 2019 at 16:05
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)

  0 Comments

Sign in to comment.

Products


Release

R2017b

1 Answer

Answer by Adam Danz
on 18 Jul 2019
 Accepted Answer

" 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

Show 1 older comment
I'm not sure what you're asking. If the date and time are stored (in different fields) in the structure, what's the problem accesssing those different fields? Maybe an example would help.
One interpretation of your question is this (you can correct me where I go awry): the user selects a date-time from the inputdlg such as "03/16/1979 3:16". The dates are stored in s.Dates and the times are stored in s.Time and you're wondering how to find the index of the correct date/time.
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.
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.