检测 no.of 按钮点击 Matlab Gui

Detect no.of Button clicks Matlab Gui

有没有办法检测在 Matlab Gui 中单击按钮的 no.of 次?我是新手,非常感谢您的帮助。

举个例子。这使用按钮的 'UserData' 属性 来保持计数器。旧语法(R2014b 之前的版本)用于获取和设置属性:

h = uicontrol('style', 'pushbutton', 'string', 'Push me'); %// create button
set(h, 'UserData', 0); %// initiallize counter
set(h, 'callback', 'set(gcbo,''UserData'',get(gcbo,''UserData'')+1)'); %// increase counter

现在点击按钮几次,得到点击次数

get(h, 'Userdata')