Too many input arguments to uicontrol callback

人走茶凉 提交于 2019-12-11 15:03:36

问题


I am trying to write a scroll bar that changes the x-range of many subplots at the same time.

kids = get(gcf,'Children');
 h=uicontrol('style','slider',...
'units','normalized','position',Newpos,...
'callback',{@slide_axes,kids},'min',0,'max',xmax-chunkDuration);

Update_axes is defined in the same file:

function slide_axes(h)
 set(h,'xlim',get(gcbo,'value')+[0 20000]); 

end

However, I get the error:

??? Error using plot_scroll>slide_axes
Too many input arguments.

??? Error while evaluating uicontrol Callback

I read on the FEX that callback may pass two arguments to any callback function. However, when I changed the signature of slide_axes to slide_axes(h,evt) the error remains.


回答1:


The arguments you are passing (h and evt) are MATLAB defaults. If you want to pass additional arguments to your callback function you need to write them after h and evt. Like this:

function slide_axes(h, evt, k)
    % k is kids.
end


来源:https://stackoverflow.com/questions/14359231/too-many-input-arguments-to-uicontrol-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!