uicontrol callback function with single variable
4 views (last 30 days)
Show older comments
I am trying to create a GUI that will have multiple pushbuttons which I want to reference the same callback function with the caveat being that the only piece that changes in the callback function is a single variable which I want to pass to the function in the syntax for the uicontrol. For example, lets say i have the following uicontrols
%pushbutton for 1x line bet
uicontrol('Parent',display,...
'Style','pushbutton',...
'String','1x',...
'Units','normalized',...
'Position',[0.8,0.70,0.15,0.06],...
'Callback',{@test,1});
%pushbutton for 2x line bet
uicontrol('Parent',display,...
'Style','pushbutton',...
'String','2x',...
'Units','normalized',...
'Position',[0.8,0.60,0.15,0.06],...
'Callback',{@test,2});
%pushbutton for 5x line bet
uicontrol('Parent',display,...
'Style','pushbutton',...
'String','3x',...
'Units','normalized',...
'Position',[0.8,0.50,0.15,0.06],...
'Callback',{@test,3});
and lets say this is my callback function
function test(multiple)
x = [0,1,2,3];
y = multiple .* x
end
I've tried it both the way that I have it shown in my example as well as changing the syntax for the callback function to function test(multiple, ~) and the uicontrol syntax to {@test,1,~} for example with no sucess either way. Both cases give me an error that says I have too many input arguments. Can anyone tell me what I'm doing wrong?
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!