GUI access data from other callback functions
4 次查看(过去 30 天)
显示 更早的评论
So, I am following some of the examples like I found on the internets. But I just can not seem to access data/variables set by other callback functions in my GUI. Basically my GUI is just having the user config some values, and then I have two buttons which pass those values to functions. But I just can not access the variables set in those other callback functions!
Attached below is my GUI code.
Any input?
function varargout = DiracGUI(varargin)
% DIRACGUI MATLAB code for DiracGUI.fig
% DIRACGUI, by itself, creates a new DIRACGUI or raises the existing
% singleton*.
%
% H = DIRACGUI returns the handle to a new DIRACGUI or the handle to
% the existing singleton*.
%
% DIRACGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DIRACGUI.M with the given input arguments.
%
% DIRACGUI('Property','Value',...) creates a new DIRACGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DiracGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DiracGUI_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 DiracGUI
% Last Modified by GUIDE v2.5 07-Jul-2012 16:40:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DiracGUI_OpeningFcn, ...
'gui_OutputFcn', @DiracGUI_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 DiracGUI is made visible.
function DiracGUI_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 DiracGUI (see VARARGIN)
% Choose default command line output for DiracGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DiracGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DiracGUI_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 countingBox.
function countingBox_Callback(hObject, eventdata, handles)
% hObject handle to countingBox (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 countingBox
if get(hObject,'Value') == true;
count = true;
else
count = false
end
% --- Executes on button press in avgBox.
function avgBox_Callback(hObject, eventdata, handles)
% hObject handle to avgBox (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 avgBox
if get(hObject,'Value')== true
avg = true;
else
avg = false;
end
function chanAThresh_Callback(hObject, eventdata, handles)
% hObject handle to chanAThresh (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 chanAThresh as text
% str2double(get(hObject,'String')) returns contents of chanAThresh as a double
chanAThreshhold = str2num(get(hObject,'String'))
% --- Executes during object creation, after setting all properties.
function chanAThresh_CreateFcn(hObject, eventdata, handles)
% hObject handle to chanAThresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function chanBThresh_Callback(hObject, eventdata, handles)
% hObject handle to chanBThresh (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 chanBThresh as text
% str2double(get(hObject,'String')) returns contents of chanBThresh as a double
chanBThreshhold = str2num(get(hObject,'String'))
% --- Executes during object creation, after setting all properties.
function chanBThresh_CreateFcn(hObject, eventdata, handles)
% hObject handle to chanBThresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function chanCThresh_Callback(hObject, eventdata, handles)
% hObject handle to chanCThresh (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 chanCThresh as text
% str2double(get(hObject,'String')) returns contents of chanCThresh as a double
chanCThreshhold = str2num(get(hObject,'String'))
% --- Executes during object creation, after setting all properties.
function chanCThresh_CreateFcn(hObject, eventdata, handles)
% hObject handle to chanCThresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function chanDThresh_Callback(hObject, eventdata, handles)
% hObject handle to chanDThresh (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 chanDThresh as text
% str2double(get(hObject,'String')) returns contents of chanDThresh as a double
chanDThreshold = str2num(get(hObject,'String'))
% --- Executes during object creation, after setting all properties.
function chanDThresh_CreateFcn(hObject, eventdata, handles)
% hObject handle to chanDThresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in chanA.
function chanA_Callback(hObject, eventdata, handles)
% hObject handle to chanA (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 chanA
if get(hObject,'Value') == true
channelAEnabled = true;
else
channelAEnabled = false;
end
% --- Executes on button press in chanB.
function chanB_Callback(hObject, eventdata, handles)
% hObject handle to chanB (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 chanB
if get(hObject,'Value') == true
channelBEnabled = true;
else
channelBEnabled = false;
end
% --- Executes on button press in chanC.
function chanC_Callback(hObject, eventdata, handles)
% hObject handle to chanC (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 chanC
if get(hObject,'Value') == true
channelCEnabled = true;
else
channelCEnabled = false;
end
% --- Executes on button press in chanD.
function chanD_Callback(hObject, eventdata, handles)
% hObject handle to chanD (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 chanD
if get(hObject,'Value') == true
channelDEnabled = true;
else
channelDEnabled = false;
end
% --- Executes on button press in showImages.
function showImages_Callback(hObject, eventdata, handles)
% hObject handle to showImages (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 showImages
if get(hObject,'Value') == true
showImages = true;
else
showImages = false;
end
% --- Executes on button press in saveRaw.
function saveRaw_Callback(hObject, eventdata, handles)
% hObject handle to saveRaw (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 saveRaw
if get(hObject,'Value') == true
saveRaw = true;
else
saveRaw = false;
end
function saveLocation_Callback(hObject, eventdata, handles)
% hObject handle to saveLocation (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 saveLocation as text
% str2double(get(hObject,'String')) returns contents of saveLocation as a double
% --- Executes during object creation, after setting all properties.
function saveLocation_CreateFcn(hObject, eventdata, handles)
% hObject handle to saveLocation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
filePath = get(hObject,'String');
function sweepsPerLine_Callback(hObject, eventdata, handles)
% hObject handle to sweepsPerLine (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 sweepsPerLine as text
% str2double(get(hObject,'String')) returns contents of sweepsPerLine as a double
sweepsPerLine = str2num(get(hObject,'String'));
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function sweepsPerLine_CreateFcn(hObject, eventdata, handles)
% hObject handle to sweepsPerLine (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in initAlazar.
function initAlazar_Callback(hObject, eventdata, handles)
% hObject handle to initAlazar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
configureAlazar();
% --- Executes on button press in acquireData.
function acquireData_Callback(hObject, eventdata, handles)
% hObject handle to acquireData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
runDIRAC(sweepsPerLine, ChannelAEnabled, ChannelBEnabled, ChannelCEnabled, ChannelDEnabled, filePath, saveRaw, showImages, count, chanAThreshhold, chanBThreshhold, chanCThreshhold, chanDThreshhold)
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!