Home Warning when passing arguments to a GUIDE GUI
Reply: 1

Warning when passing arguments to a GUIDE GUI

Aero Engy
Aero Engy Published in 2017-12-08 01:16:41Z

I am trying to pass arguments to a GUIDE generated GUI. This works but throws a Warning.

inputTest('Passed In String')

Warning: The input to STR2FUNC "Passed In String" is not a valid function name. This will generate an error in a future release.

I know I have passed arguments to GUIDE GUIs in the past and I don't recall ever seeing this warning message before. However, I am relatively new to Matlab 2016b so something may have changed that I am not aware of. I didn't find anything in the documentation.

The warning occurs in the "initialization code - DO NOT EDIT" auto generated section and only happens when passing in an optional argument.

Is this a bug in 2016b or have I missed something?

Minimal Example below. It is a simple GUI with only a single Edit box.

function varargout = inputTest(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @inputTest_OpeningFcn, ...
                   'gui_OutputFcn',  @inputTest_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1}); % WARNING OCCURS HERE

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    gui_mainfcn(gui_State, varargin{:});
% End initialization code - DO NOT EDIT

function inputTest_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% Fill the box if the string is passed in.
if nargin == 4
    handles.edit1.String = varargin{1};
    handles.edit1.String = 'Nothing Passed In';
guidata(hObject, handles);

function varargout = inputTest_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;

function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
excaza Reply to 2017-12-08 02:28:20Z

The default GUIDE GUI behavior is explained in the autogenerated inline documentation:

% ASDF MATLAB code for asdf.fig
%      ASDF, by itself, creates a new ASDF or raises the existing
%      singleton*.
%      H = ASDF returns the handle to a new ASDF or the handle to
%      the existing singleton*.
%      ASDF('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ASDF.M with the given input arguments.
%      ASDF('Property','Value',...) creates a new ASDF or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before asdf_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to asdf_OpeningFcn via varargin.

The syntax you're attempting to use is the syntax reserved for calling callbacks that are local to your GUI, which is why it's using a str2func call on the first input. Either remove the str2func call or change your input syntax to accept a separate output than what GUIDE is designed for.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.41152 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO