Initialising buttons so that the button text changes when said button is pressed
10 次查看(过去 30 天)
显示 更早的评论
How can I give a set of state buttons the same callback to change the text on the button that is pressed? I have 10 buttons that say "connect" and when I click one, I want it to say "connecting". I could do this by creating a personalised callback function for each button, but how can I do it by creating one function that all buttons can use? I currently have this but hObject is definitely not working as I intended.
function Connect(app, hObject)
if hObject == true
TotalValueCheck(app)
% function for receivers to intercept signal is executed
% while:
hObject.Text = 'Connecting...';
%elseif signal detected from rover = true
% app.ConnectButton_1.Text = 'Connected'
elseif hObject == false
hObject.Text = 'Connect';
end
end
0 个评论
采纳的回答
Kevin Holly
2022-7-19
编辑:Kevin Holly
2022-7-19
Barney,
Please see app attached. I added a public function as such:
methods (Access = public)
function func(app,hObject)
if hObject.Value==1
hObject.Text = 'Connecting...';
else
hObject.Text = 'Connect';
end
end
end
Then I added callback functoins referencing it.
% Value changed function: Button
function ButtonValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button2
function Button2ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button3
function Button3ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button4
function Button4ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button5
function Button5ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button6
function Button6ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button7
function Button7ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button8
function Button8ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button9
function Button9ValueChanged(app, event)
func(app,event.Source)
end
% Value changed function: Button10
function Button10ValueChanged(app, event)
func(app,event.Source)
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!