MATLAB Answers

Input array through GUIDE

2 views (last 30 days)
Oscar Espinosa
Oscar Espinosa on 9 Mar 2018
Answered: Walter Roberson on 9 Mar 2018
I'm trying to introduce data through GUIDE like a vector. I get an error on the function in which the vector is introduced. The error is the following:
Undefined function or variable 'varargin'.
Error in m (line 3)
s_lz=varargin{1};
Error in Interface_for_optimal_values_1>pushbutton1_Callback (line 34)
[Result,Inp,lz,nu,str,c_,f0,fk]=m(hObject,eventdata,handles);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Interface_for_optimal_values_1 (line 16)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Interface_for_optimal_values_1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
The GUI's code is the following:
function pushbutton1_Callback(hObject, eventdata, handles)
handles.s_lz=double(handles.lz0):double(handles.lz_step):double(handles.lzf);
handles.s_nu=double(handles.nu0):double(handles.nu_step):double(handles.nuf);
[Result,Inp,lz,nu,str,c_,f0,fk]=m(hObject,eventdata,handles,varargin);
and the function's code:
function [Result,Inp,lz,nu,str,c_,f0,fk]=m(hObject,eventdata,handles,varargin)
s_lz=varargin{1};
s_nu=varargin{2};
s_srt=varargin{3};
s_ak=varargin{4};
s_c=varargin{5};
s_c_k_koef=varargin{6};
s_f0=varargin{7};
s_fk=varargin{8};

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 9 Mar 2018
You have
function pushbutton1_Callback(hObject, eventdata, handles)
handles.s_lz=double(handles.lz0):double(handles.lz_step):double(handles.lzf);
handles.s_nu=double(handles.nu0):double(handles.nu_step):double(handles.nuf);
[Result,Inp,lz,nu,str,c_,f0,fk]=m(hObject,eventdata,handles,varargin);
You cannot pass varargin in the call to m() because varargin is only defined in functions that refer to varargin in the function statement. Your function pushbutton1_Callback does not refer to varargin in the function line, so varargin cannot be used inside that function.
varargin is a special name that should only be used when the calling functions have a choice as to how many parameters to pass in. Inside a function, it should not be used without testing how many arguments were passed, or at least not without testing the size of varargin. Your code for m assumes that varargin is length 8 or more -- assumes, in other words, that any call to m has passed in at least 8 individual parameters after pasing in hObject, eventdata, and handles. In any case where you have a definite number of individual parameters that are required, you should be using named parameters instead of varargin. Or you should be changing your calling sequence to expect a named cell array or struct array or numeric array at that point that the caller packs the arguments into.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!