Chris Herrera
Chris Herrera

Reputation: 61

Matlab Too many output arguments from GUI figure declaration

I have a GUI that I want to catch errors for and handle with a function I have called generateReport. The first GUI file (there are multiple windows each with it's own programmatic GUI file) is CSTMainWindow and the Program is run from the Celest function.

CeleST:

function CeleST

c(@CSTMainWindow); % line 3

end

c.m is just a wrapper for functions so I can try/catch them so I don't have to write code in every subfunction

function c(fxn)
% Function to wrap callback functions with try/catch and call
% generateReport.m in case of error

try
    fxn(); % line 6
catch exception
    generateReport(exception)
end

end

So CSTMainWindow is called but then it breaks on this line (the first GUI code line really) CSTMainWindow.m line 142:

mainFigure = figure('Visible','off','Position',[5,40,mainW,mainH],'Name','CeleST: Check results','numbertitle','off', 'menubar', 'none', 'resizefcn', c(@resizeMainFigure));

When debugging, c.m catches the error:
identifier: 'MATLAB:TooManyOutputs'
message: 'Too many output arguments.'
stack:
line name
142 CSTMainWindow
6 c
3 CeleST

In trying to resolve this I found that changing the callback to just resizeMainFigure fixes it which makes sense, but then to get the try/catch behavior I want, I would have to but a block everywhere which I was doing before and I'm trying to avoid.

My question is why am I getting too many output arguments if CSTMainWindow has zero output arguments and neither does resizeMainFigure (below for reference)

function resizeMainFigure(hObject,eventdata) %#ok<INUSD>
        % -------
        % Update the size and position of the sliders
        % -------
        newPosition = get(mainFigure,'position');
        set(sliderHoriz, 'position',[0 0 newPosition(3)-20 20]);
        set(sliderVert, 'position',[newPosition(3)-20 20 20 newPosition(4)-20]);
        % -------
        % Check the horizontal slider
        % -------
        if newPosition(3) < mainPanelPosition(3)
            deltaH = round(mainPanelPosition(3) - newPosition(3));
            newValue = min(deltaH,get(sliderHoriz,'value'));
            set(sliderHoriz, 'enable', 'on', 'min',0,'max',deltaH,'value',newValue);
        else
            set(sliderHoriz, 'enable', 'off','min',0,'max',1,'value',0);
        end
        % -------
        % Check the vertical slider
        % -------
        if newPosition(4) < mainPanelPosition(4)
            deltaV = round(mainPanelPosition(4) - newPosition(4));
            newValue = min(deltaV,get(sliderVert,'value'));
            set(sliderVert, 'enable', 'on', 'min',0,'max',deltaV,'value',newValue);
        else
            set(sliderVert, 'enable', 'off','min',0,'max',1,'value',0);
        end
        setMainPanelPositionBySliders
end

Upvotes: 0

Views: 365

Answers (1)

Clarissa G
Clarissa G

Reputation: 341

Check the last argument to figure that you have. It's a function call to c, which returns nothing, but you're passing it as a parameter to the figure call. c has no return value but, in effect, you're asking for it to return a value for you. Based on the figure documentation, you have to provide a function handle, a cell array containing a function handle, or a string that is a valid MATLAB expression for resizefcn. You might try turning your function call into a string instead:

mainFigure = figure('Visible','off','Position',[5,40,mainW,mainH],'Name','CeleST: Check results','numbertitle','off', 'menubar', 'none', 'resizefcn', 'c(@resizeMainFigure)');

Upvotes: 3

Related Questions