Please help me i get the error "Undefined function or variable 'varargin'. Error in Question4 (line 16) gui_mainfcn(gui_State, varargin{:});"

function varargout = Question4(varargout)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Question4_OpeningFcn, ...
'gui_OutputFcn', @Question4_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargin{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function open_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg')
imshow(flip(a,1));
function Question4_OpeningFcn(hObject, evendata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function horizontal_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg');
imshow(flip(a,1));
function vertical_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg');
imshow(flip(a,2));

Respuestas (2)

Phiri - your function signature is
function varargout = Question4(varargout)
where the input and output parameters/arguments are the same name. I think the input should be variable argument in or varargin
function varargout = Question4(varargin)

10 comentarios

Thank you very much. I just tried that though and more errors come out.
Using varargin in the function definition is the correct thing to do.
We would need to see the error messages and code that was relevant to them.
function varargout = Question4(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Question4_OpeningFcn, ...
'gui_OutputFcn', @Question4_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargin{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function open_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg')
imshow(flip(a,1));
function Question4_OpeningFcn(hObject, evendata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function horizontal_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg');
imshow(flip(a,1));
function vertical_Callback(hObject, evendata, handles)
a = imread('cristiano-ronaldo-goal-lebron-zlatan-01-960x640.jpg');
imshow(flip(a,2));
The Error messages are as follows.
Error using load
Unable to read file 'Question4.fig'. No such file or directory.
Error in matlab.graphics.internal.figfile.FigFile/read (line 31)
hgDataVars = load(filename, '-mat', '-regexp', '^hg[M]');
Error in matlab.graphics.internal.figfile.FigFile
Error in hgload (line 54)
FF = matlab.graphics.internal.figfile.FigFile(filename);
Error in matlab.hg.internal.openfigLegacy (line 57)
[fig, savedvisible] = hgload(filename, struct('Visible','off'));
Error in gui_mainfcn>local_openfig (line 286)
gui_hFigure = matlab.hg.internal.openfigLegacy(name, singleton, visible);
Error in gui_mainfcn (line 158)
gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt, gui_Visible);
Error in Question4 (line 16)
gui_mainfcn(gui_State, varargin{:});
"Unable to read file 'Question4.fig'. No such file or directory."
Well that should be self-explanatory. You do not have a Question4.fig file. GUIDE-created interfaces create a .fig file along with the .m file, and you need both.
One way this problem can arise is if you took a GUIDE-created .m file and renamed it without renaming the .fig as well.
On the other hand, you should not just rename the .m and .fig files, as some of what is created by GUIDE depends upon the file name. You should instead go into GUIDE and "Save As" the new name.
i don't know how i'm supposed to do that to be honest.
Rename the files back to the name you used when you created them. Open the GUI inside GUIDE. Then go to the File menu and click on Save As, and select the new name (that is, Question4)
That is the name i used. It was just the image and then the m.file in one folder.
Did you write all that code by hand, or did you use GUIDE to create it? GUIDE would have created a .fig file to go along with the .m file. Perhaps you created it in a different directory and moved (or copied) Question4.m without also taking along Question4.fig ?
i used hand to write the code not guide
The line
[varargin{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
invokes gui_mainfcn which attempts to load a .fig with the same name as your .m file. gui_mainfcn also is the routine responsible for creating the handles structure, and for calling your Question4_OpeningFcn .
Your code is not creating any uicontrol or menu items, so horizontal_Callback and vertical_Callback have nothing referencing them. You did not set either of them as being callbacks for anything.
In short, if you are going to write your own GUI code without using GUIDE, then you should not use the template that GUIDE uses. You need to instead have code that creates the figure and uicontrol and sets up all appropriate callbacks, and then lets the user interact with the GUI.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Abr. de 2018

Comentada:

el 26 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by