f = figure;
data.numberOfClicks = 0;
guidata(f,data)
f.ButtonDownFcn = @My_Callback;
function My_Callback(src,event)
data = guidata(src);
data.numberOfClicks = data.numberOfClicks + 1;
guidata(src,data)
data
end
% --- Executes just before countClicks is made visible.function countClicks_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 countClicks (see VARARGIN)% Choose default command line output for countClicks
handles.output = hObject;
handles.numberOfClicks = 0;
% Update handles structure
guidata(hObject, handles);
% --- 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)
handles.numberOfClicks = handles.numberOfClicks + 1;
guidata(hObject,handles)
data = guidata(hObject)
>> countClicks
data =
struct with fields:
figure1: [1×1 Figure]
pushbutton1: [1×1 UIControl]
output: [1×1 Figure]
numberOfClicks: 1
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.