Matlab GUI callback troubles

前端 未结 2 1582
忘掉有多难
忘掉有多难 2021-01-29 06:56

I try to make the uipanel change boarder colors while pressing and releasing mouse button on elsewhere except inputs and panel buttons.

function    [oldpropvalu         


        
相关标签:
2条回答
  • 2021-01-29 07:11

    Your problem is that you're defining your window callbacks as character vectors, which are evaluated in the base workspace where the variable varargin doesn't exist. You can define them as anonymous functions instead:

    set(varargin{1}, 'WindowButtonDownFcn', ...
        @(~, ~) set(varargin{2}, 'BorderType', 'line', 'BorderWidth', 2, ...
                    'HighlightColor', [0 0 0]));
    set(varargin{1}, 'WindowButtonUpFcn', ...
        @(~, ~) set(varargin{2}, 'BorderType', 'beveledout', 'BorderWidth', 1, ...
                    'HighlightColor', [1 1 1]));
    
    0 讨论(0)
  • 2021-01-29 07:13

    You did not show how you produced the error, but from the error message, I guess you called the function with less than 4 input arguments. Then varargin does not exist, so matlab gives the error.

    To avoid the error, you need to check nargin before you use varargin, for example, replace your if statement line with

    if nargin==5 % so length(varargin)==2
    
    0 讨论(0)
提交回复
热议问题