Error while evaluating UIControl Callback on pushbotton - matlab

I am trying to create a button in GUI matlab and call a function when it is pressed. This code it is not working
the code is:
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)
pushbutton2=handles.pushbutton2;
popupmenu1 = get(handles.popupmenu1, 'value');
if popupmenu1 == 1
load 'dataa.mat'
load 'unnamed.mat'
training=dataa(1:21,:);
train_class=unnamed(1:21);
testing=dataa(2:21,:);
test_class=unnamed(2:21);
model=fitcnb(training,train_class);
hasil_pelatihan = predict(model, training);
jumlah_benar = 0;
for k = 1:21
if isequal(hasil_pelatihan(k),train_class(k))
jumlah_benar = jumlah_benar+1;
end
end
akurasi_pelatihan = jumlah_benar/21*100
model=fitcnb(testing,test_class);
hasil_pengujian = predict(model, testing);
jumlah_benar = 0;
for k = 1:30
if isequal(hasil_pengujian(k),test_class(k))
jumlah_benar = jumlah_benar+1;
end
end
akurasi_pengujian = jumlah_benar/30*100
set(handles.edit2,'String',akurasi_pelatihan);
set(handles.edit3,'String',akurasi_pengujian);
the output is:
Error in
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)trial('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
So the function works since it is called twice but when I press the button it crashes. I dont want to use more than one file. Thank you.

Related

Passing values from radio buttons into the script in Matlab

So i created GUI in guide that looks like this:
GUI
I want to access data from radio button and then change the variables in my simulation (Bitrate and Modulation are the button groups, Improvement is a single radio button). For example - in the simulation I have a variable Rs=1e9, so when 1Gbps button is selected I want it to remain 1e9, but if 10Gbps button is selected I want it to change its value to 10e9.
Then after hitting Start button I want to start my simulation (which is in different .m file) with given parameters. How can I do it ? (I know about handles idea in matlab, but I don't know how to pass value to the simulation)
That's the code that controls gui - generated by guide. I added some code that starts simulation and close gui window.
function varargout = gui_final(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #gui_final_OpeningFcn, ...
'gui_OutputFcn', #gui_final_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui_final is made visible.
function gui_final_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for gui_final
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui_final wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_final_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
close all
message = sprintf('Wait - this is a very long simulation!\nClick the OK button and wait');
uiwait(msgbox(message));
evalin('base', 'simulation');
% --- Executes on button press in dfe.
function dfe_Callback(hObject, eventdata, handles)
% hObject handle to dfe (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of dfe
% --- Executes on button press in ook.
function ook_Callback(hObject, eventdata, handles)
% hObject handle to ook (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ook
You can do it using the object "hObject"
Like this: Suppose that you have an slider, everytime the slider is moved the callback is called. You can use it to store a variable. Then, when you press a button you want to use that data for whatever. The code is:
function slider_callback(hObject,eventdata)
sval = hObject.Value;
diffMax = hObject.Max - sval;
data = struct('val',sval,'diffMax',diffMax);
hObject.UserData = data;
% For R2014a and earlier:
% sval = get(hObject,'Value');
% maxval = get(hObject,'Max');
% diffMax = maxval - sval;
% data = struct('val',sval,'diffMax',diffMax);
% set(hObject,'UserData',data);
end
function button_callback(hObject,eventdata)
h = findobj('Tag','slider1');
data = h.UserData;
% For R2014a and earlier:
% data = get(h,'UserData');
display([data.val data.diffMax]);
end
REFERENCE: Matlab Docs
UPDATE
In your case you can do it with another approach if you want. When you press the button START you read the state of your radio buttons, and pass the appropiate value to your simulation_function that I suppose it is called "simulation". In the following example I suppose that you have a button-group called (tag): uibuttongroup1, and inside you have two buttons: radiobutton1 and radiobutton2
% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Check which radio button is pressed
switch get(get(handles.uibuttongroup1,'SelectedObject'),'Tag')
case 'radiobutton1', myParameter = 1e9;
case 'radiobutton2', myParameter = 10e9;
end
%Execute simulation
clc
close all
message = sprintf('Wait - this is a very long simulation!\nClick the OK button and wait');
uiwait(msgbox(message));
evalin('base', 'simulation(myParameter)');

Matlab - two active GUIs

I have one GUI (GUI1) with Button (Btn1). When I click the Btn1 a second window with plot (GUI2) appers and GUI1 becomes inactive (GUI2.fig and GUI.m are saved to disk). How to make both windows active?
I've tride something like this but it did not work:
InterfaceObj=findobj(fig,'Enable','on'); % fig = gcf;
set(InterfaceObj,'Enable','on');
GUI2 is invoked as follows:
h = GUI2;
Thanks for the answers!
My code:
function visual_Callback(hObject, eventdata, handles) %Btn1
% hObject handle to visual (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PDB_=getappdata(gcf,'PDB_');
file_=getappdata(gcf,'file_');
set(handles.PDB_list,'String', PDB_ );
SelectedItem = get(handles.PDB_list,'Value');
setappdata(gcf,'SelectedItem',SelectedItem);
fig = gcf;
h = GUI2; % GUI2.fig and .m file
visual(file_(SelectedItem,:)); %visual() is the function that generates my graph
InterfaceObj=findobj(fig,'Enable','on');
set(InterfaceObj,'Enable','on');
end
I've done it!
I put the:
h = GUI2;
Inside the function:
mainWindow_OpeningFcn(hObject, eventdata, handles, varargin)
...
guidata(hObject, handles);
h = GUI2;
end
This initialized GUI2 with GUI1 startup.
Thank You very much!

My matlab while loop isn't recognising my function button press

I have a script that runs when a button is pressed causing a while loop to initiate. When my stop button is pressed it is supposed to cause the loop condition to be untrue thus stopping the loop. My stop button doesn't seem to stop the loop during testing. it would seem the value I assigned in the pushDisconnect button isn't updating to the while loop and i'm not sure why this is occurring.
% --- Executes on button press in pushConnect.
function pushConnect_Callback(hObject, eventdata, handles)
% hObject handle to pushConnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','on')
set(handles.pushConnect,'Enable','off')
handles.myDevice.StartAcquisition;
sampleRate_BP = double(handles.myDevice.BioPotentialSignals.SamplesPerSecond);
axis_handles = zeros(1,handles.numEnabledBPChannels);
BioPotentialSignals = cell(1,handles.numEnabledBPChannels);
handles.CheckFinger = cell(1,5);
handles.stopNow = 0;
for ch = 1:handles.numEnabledBPChannels
axis_handles(ch) = subplot(length(axis_handles),1,ch,'Parent',handles.uipanelGraph);
if ch==1
title(char(handles.deviceName))
end
ylabel([char(handles.myDevice.BioPotentialSignals.Item(ch-1).Name) ' (V)']);
hold on
end
xlabel('Time (s)')
linkaxes(axis_handles,'x')
plotWindow = 5;
plotGain_BP = 1;
while handles.stopNow == 0
for ch = 1:handles.numEnabledBPChannels
BioPotentialSignals{ch} = [BioPotentialSignals{ch};handles.myDevice.BioPotentialSignals.Item(ch-1).GetScaledValueArray.double'];
if length(BioPotentialSignals{ch}) <= plotWindow*sampleRate_BP
cla(axis_handles(ch))
t = (0:(length(BioPotentialSignals{ch})-1))*(1/sampleRate_BP);
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch});
xlim([0 plotWindow])
else
if ch==1
t = ((length(BioPotentialSignals{ch})-(plotWindow*sampleRate_BP-1)):length(BioPotentialSignals{ch}))*(1/sampleRate_BP);
end
cla(axis_handles(ch))
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch}(end-plotWindow*sampleRate_BP+1:end));
xlim([t(end)-plotWindow t(end)])
end
end
% Update handles structure
guidata(hObject, handles);
pause(0.1)
disp(handles.stopNow)
end
% Stop signal
handles.myDevice.StopAcquisition;
% Disconnect from all sensors
handles.myDevice.Disconnect;
msgbox('Device requires cycling, in order to restablish connection. Closing program.')
% Close window
close all;
% --- Executes on button press in pushDisconnect.
function pushDisconnect_Callback(hObject, eventdata, handles)
% hObject handle to pushDisconnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','off')
handles.stopNow = 1;
% Update handles structure
guidata(hObject, handles);
Final Working Code, if anyone is interested:
% --- Executes on button press in pushConnect.
function pushConnect_Callback(hObject, eventdata, handles)
% hObject handle to pushConnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','on')
set(handles.pushConnect,'Enable','off')
handles.myDevice.StartAcquisition;
sampleRate_BP = double(handles.myDevice.BioPotentialSignals.SamplesPerSecond);
axis_handles = zeros(1,handles.numEnabledBPChannels);
BioPotentialSignals = cell(1,handles.numEnabledBPChannels);
handles.CheckFinger = cell(1,5);
handles.stopNow = 0;
for ch = 1:handles.numEnabledBPChannels
axis_handles(ch) = subplot(length(axis_handles),1,ch,'Parent',handles.uipanelGraph);
if ch==1
title(char(handles.deviceName))
end
ylabel([char(handles.myDevice.BioPotentialSignals.Item(ch-1).Name) ' (V)']);
hold on
end
xlabel('Time (s)')
linkaxes(axis_handles,'x')
plotWindow = 5;
plotGain_BP = 1;
% Update handles structure
guidata(hObject, handles);
while handles.stopNow == 0
for ch = 1:handles.numEnabledBPChannels
BioPotentialSignals{ch} = [BioPotentialSignals{ch};handles.myDevice.BioPotentialSignals.Item(ch-1).GetScaledValueArray.double'];
if length(BioPotentialSignals{ch}) <= plotWindow*sampleRate_BP
cla(axis_handles(ch))
t = (0:(length(BioPotentialSignals{ch})-1))*(1/sampleRate_BP);
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch});
xlim([0 plotWindow])
else
if ch==1
t = ((length(BioPotentialSignals{ch})-(plotWindow*sampleRate_BP-1)):length(BioPotentialSignals{ch}))*(1/sampleRate_BP);
end
cla(axis_handles(ch))
plot(axis_handles(ch),t,plotGain_BP*BioPotentialSignals{ch}(end-plotWindow*sampleRate_BP+1:end));
xlim([t(end)-plotWindow t(end)])
end
end
handles = guidata(hObject);
drawnow
pause(0.1)
end
% Stop signal
handles.myDevice.StopAcquisition;
% Disconnect from all sensors
handles.myDevice.Disconnect;
msgbox('Device requires cycling, in order to restablish connection. Closing program.')
% Close window
close all;
% --- Executes on button press in pushDisconnect.
function pushDisconnect_Callback(hObject, eventdata, handles)
% hObject handle to pushDisconnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.pushDisconnect,'Enable','off')
handles.stopNow = 1;
% Update handles structure
guidata(hObject, handles);
Kill the guidata(hObject, handles) line, and replace it by handles=guidata(hObject) since you're overwriting the GUI state with whatever was current at the time the loop started, and you want to be polling the GUI state instead. Put the guidata(hObject, handles)-line before the loop, to ensure that handles.stopNow is indeed reset to 0.
If that doesn't help, an additional problem may be that Matlab waits with processing commands from one button callback until the other callback is done running.
Two things you can try: Add a drawnow command before the pause. This will force the GUI to update, and processes all the interactions. Also, make sure that the pushbutton callback for pushConnect is interruptible.

Matlab GUI/GUIDE Appending item to vector stored in in a handle

I'm working on a program that records user button-presses in response to a sequence of tones. I am storing the timing of the button presses in a vector (pushTimes), which I am storing in GUIDE's "handles" structure, and I would like the new time of each button press to be appended to the pushTimes vector. However, handles doesn't seem to be storing the new vector with the appended value, leaving me with an empty vector after the button is pressed.
Edit: Because people were having difficulty reproducing the error, I'm posting the whole file The relevant code is in the callBack pushButton1. pushButton2 and pushButton3 are "pause" and "start" buttons, respectively. The error occurs even when I don't pause the program.
function varargout = simpleGui(varargin)
% SIMPLEGUI M-file for simpleGui.fig
% SIMPLEGUI, by itself, creates a new SIMPLEGUI or raises the existing
% singleton*.
%
% H = SIMPLEGUI returns the handle to a new SIMPLEGUI or the handle to
% the existing singleton*.
%
% SIMPLEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIMPLEGUI.M with the given input arguments.
%
% SIMPLEGUI('Property','Value',...) creates a new SIMPLEGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before simpleGui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to simpleGui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help simpleGui
% Last Modified by GUIDE v2.5 27-May-2014 11:00:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', #simpleGui_OpeningFcn, ...
'gui_OutputFcn', #simpleGui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before simpleGui is made visible.
function simpleGui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to simpleGui (see VARARGIN)
[soundVec, codeVec] = FourToneDifDirection();
handles.soundVec = soundVec;
handles.codeVec = codeVec;
handles.toneTimes = zeros(1,length(soundVec));
handles.pushTimes = [];
handles.toneNum = 1;
% Choose default command line output for simpleGui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes simpleGui wait for user response (see UIRESUME)
% --- Outputs from this function are returned to the command line.
function varargout = simpleGui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function handles = 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)
dv = datevec(now);
%get the seconds from datevec
sec = dv(6);
%append to the pushTimes vector
handles.pushTimes = [handles.pushTimes sec]
%debugging line, should return a large vector after button is pressed multiple times but only returns a single value.
handles.pushTimes
guidata(hObject, handles)
% --- Executes on button press in pushbutton2.
function pushbutton2_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)
UIresume
guidata(hObject, handles);
soundVec = handles.soundVec
n = 1;
while(n<length(soundVec))
guidata(hObject, handles);
n = handles.toneNum
midigen(handles.soundVec(n), 0.25);
dv = datevec(now);
sec = dv(6);
handles.toneTimes(n) = sec;
n = n+1;
handles.toneNum = n;
end
guidata(hObject, handles)
% --- 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)
guidata(hObject, handles);
codeVec = handles.codeVec;
toneTimes = handles.toneTimes;
pushTimes = handles.pushTimes
calculateHitRate(codeVec, toneTimes, pushTimes,1,handles.toneNum);
guidata(hObject, handles)
uiwait(handles.figure1);
function out = isWithin(x, low, high)
out = x > low & x < high;
function [d1hr, d2hr, d3hr, d4hr] = calculateHitRate(codeVec, toneTimes, pushTimes, start, finish)
d1Ct = sum(codeVec(start:finish) == 9);
d2Ct = sum(codeVec(start:finish) == 10);
d3Ct = sum(codeVec(start:finish) == 11);
d4Ct = sum(codeVec(start:finish) == 12);
d1Push = 0;
d2Push = 0;
d3Push = 0;
d4Push = 0;
for i = 1:length(pushTimes)
pushTime = pushTimes(i)
stimTime = pushTime - 2;
for j = start:finish
%if the stimulus was within 1.5 seconds before the push
if codeVec(j) == 9 && isWithin(toneTimes(j), stimTime, pushTime)
d1Push = d1Push+1;
elseif codeVec(j) == 10 && isWithin(toneTimes(j), stimTime, pushTime)
d2Push = d2Push+1;
elseif codeVec(j) == 10 && isWithin(toneTimes(j), stimTime, pushTime)
d3Push = d3Push+1;
elseif codeVec(j) == 10 && isWithin(toneTimes(j), stimTime, pushTime)
d4Push = d4Push+1;
end
end
end
d1hr = d1Push/d1Ct
d2hr = d2Push/d2Ct
d3hr = d3Push/d3Ct
d4hr = d4Push/d4Ct

Updating GUI handles when using callback

I have a GUI made from GUIDE and I cannot figure out how to update a GUI handle when I call a callback in a callback. So for instance in the function which calls the function all I have is the following:
function start_ss_Callback(hObject, eventdata, handles)
% hObject handle to start_ss (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of start_ss as text
% str2double(get(hObject,'String')) returns contents of start_ss as a double
start_hh_Callback(hObject, eventdata, handles)
and in start_hh_Callback I have the code given below but my handles.plot_holds doesn't update regardless of the fact that I have guidata(hObject, handles). Is this because I'm using it as a function? If I just go through the start_hh_Callback itself not through start_ss_Callback, it updates. However, if I use it within a callback like start_ss_Callback it does not update.
I hope my question is clear, let me know if you need clarification.
function start_hh_Callback(hObject, eventdata, handles)
% hObject handle to start_hh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of start_hh as text
% str2double(get(hObject,'String')) returns contents of start_hh as a double
axes(handles.axes1)
if isempty(handles.plot_holds)
cla
plot_button_Callback(hObject, eventdata, handles)
else
% in the event the time is changed after more than 1 plot is held then
% the additional plot times will be re evaluated for each parameter and
% the new indicies will take into affect.
myParams = get(handles.load_params_button,'string');
mystartDD = str2num(get(handles.start_dd,'string'));
mystartHH = str2num(get(handles.start_hh,'string'));
mystartMM = str2num(get(handles.start_mm,'string'));
mystartSS = str2num(get(handles.start_ss,'string'));
myendDD = str2num(get(handles.end_dd,'string'));
myendHH = str2num(get(handles.end_hh,'string'));
myendMM = str2num(get(handles.end_mm,'string'));
myendSS = str2num(get(handles.end_ss,'string'));
startFromStart = (mystartDD)*60*60*24 + (mystartHH-handles.startHour)*60*60 ...
+ (mystartMM-handles.startMinute)*60 + (mystartSS-handles.startSecond);
endFromStart = (myendDD)*60*60*24 + (myendHH-handles.startHour)*60*60 ...
+ (myendMM-handles.startMinute)*60 + (myendSS-handles.startSecond);
iStart = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time > (startFromStart+handles.startTimeOffset),1);
iEnd = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time > (endFromStart+handles.startTimeOffset),1);
if isempty(iEnd)
iEnd = length(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time);
end
cla
hold off
plot(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time(iStart:iEnd),...
handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Data(iStart:iEnd))
grid minor
box on
handles.plot_holds(1,3) = iStart;
handles.plot_holds(1,4) = iEnd;
if size(handles.plot_holds,1)>1
hold all
for ii = 2:size(handles.plot_holds)
iStart = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time > (startFromStart+handles.startTimeOffset),1);
iEnd = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time > (endFromStart+handles.startTimeOffset),1);
if isempty(iEnd)
iEnd = length(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time);
end
plot(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time(iStart:iEnd),...
handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Data(iStart:iEnd))
handles.plot_holds(ii,3) = iStart;
handles.plot_holds(ii,4) = iEnd;
end
end
end
legend(handles.myLegends{1:length(handles.myLegends)})
guidata(hObject, handles);
You'll have to load the handles again, after any handles-modifying function:
% this modifies and writes the handles to the guidata
start_hh_Callback(hObject, eventdata, handles);
% now read back the updated value
handles = guidata(hObject);
Alternatively you could also make handles the return value of you callback.
Usually this will be ignored when it's really used as a callback and when used as a "normal" function it avoids the need to re-read from guidata.
Your code could then look like this:
handles = start_hh_Callback(hObject, eventdata, handles);
with your callback redefined to:
function [handles] = start_hh_Callback(hObject, eventdata, handles)
...
end